Non-existent variable '0'

I’m having trouble with running my quicktest. You’ll see below what it is saying.

The error I’m getting is:
QUICKTEST FAILED
Error: taking_photo line 56: Non-existent variable ‘0’

My code lat 56 looks like this:
*set {current_learning} %+ology_change_mid

In my game, people have interests. Those interests (ologies) can go up or down. current_learning is the variable for holding the current interest.

The code above is to raise the value of the current interest. And it works just fine! When I play the game no error occurs and the current interest has its value raised. However, the Quicktest thinks something is wrong.

I need Quicktext to function. Any ideas?

Why the brackets?

Shouldn’t that be:
*set current_learning %+ology_change_mid

Oh, I think I get it!

*temp mathematics 0
*temp geometry 0


*temp current_learning "geometry"

*label change_class
Would you like to change your current learning?

*fake_choice
  #Yes, please. Change it to "mathematics"
    *set current_learning "mathematics"
  #Nope keep it as ${current_learning}


*label class_room
You improved your ${current_learning} + ${(%+ology_change_mid)}points!

*set {current_learning} %+ology_change_mid

???

1 Like

@Loudbeat I added the brackets when it didn’t work without them. When I do:
*set current_learning %+ology_change_mid
I get the error “Not a number: History” in which History is the variable being held by current_learning; when I used the code above, including {current_learning} this line worked and increased the History variable.

I am working in ChoiceScript IDE, if that helps.

1 Like

@Nahim_Kerman Yes, I think you might. But then why does my Quicktest tell me “Error: taking_photo line 56: Non-existent variable ‘0’”?

If this helps to explain what I am doing:

#Well, okay, but I'm not that into ${current_learning}.  (+${current_learning})
          "Well, okay," you say, "but I'm not that into ${current_learning}." 
          *set current_learning %+ology_change_mid

This should return (if current_learning is Biology):
choice option: Well, okay, but I’m not that into Biology. (+Biology)
choice result: “Well, okay,” you say, "but I’m not that into Biology.
and then The variable called Biology increases.

I was trying to be elegant. Should I just create a second variable called current_learning_score or some such, to separate the text to appear on the screen with the same text when used as a variable?

I am having a related but different issues with this one:

*comment sets the variable for raising this exhibits nostalgia level for the current exhibit variable name
*temp nostalgia_var "nostalgia_"&{current_exhibit_var}
*set nostalgia_var +1

The reader is in a museum visiting exhibits and taking photos. Each time a photo is taken of an exhibit the Nostalgia value for that exhibit increases. There are variables to hold his value such as nostalgia_whales nostalgia_dinos etc.

current_exhibit_var holds the one word name for the current exhibit (e.g. “whales” and “dinos”).

I want to concatenate nostalgia_var to hold nostalgia_[exhibit name here] so I can raises its value by one. However, the error message is “Non-existent variable ‘null’”.

If I remove the curly-cues and use:
*temp nostalgia_var “nostalgia_”&current_exhibit_var
the error is “Not a number: nostalgia_null”
However ${current_exhibit_var} returns words like “whales.”
???

Thank you all for your help. My entire project falls apart without this but I can’t see to figure out what I am doing wrong.

I’ve never used the code that way so I don’t know its limits and problems.

What I would do is a gosub to another file with the code adding the nostalgia according to the exhibit value. I think it’s simpler and it sure would work with quickest and such.

*comment current exhibit 1 = whales | 2 = dinos
*create current_exhibit 1
You are in the @{current_exhibit whales|dinos} exhibit

*if current_exhibit = 1
  *set nostalgia_whales +1
*elseif current_exhibit = 2
  *set nostalgia_dinos +1

Something like that if you get the idea. Sorry I can’t try the code now, I’m at work.
Maybe someone more knowledgeable can make your way work.

@Loudbeat
Thank you for tackling this. I think I finally understand how to articulate my problem.

I am trying to use a variable to contain the name of another variable and then act in its place.

To use my LATEST challenge (a third one now, but it appears to be functionally working when running):

*set photo_count +1
*temp photosub_hold "photosubject_"&photo_count
*set {photosub_hold} current_exhibit

photo_count is how many photos has been taken. The first line advances that count. If 2 have been taken the current count is now 3.

A new temp variable is created to use photosub_hold to hold the name of the new photo. Those names are formatted as photosubject_X, with X being the number. So I am using concatenating to create the next variable in the line. So far so good!

Now, if I use:
*set {photosub_hold} current_exhibit
to try and get, say, photosubject_3 to equal “whales” then INSTEAD photosubject_3 does not change but, alas, photosub_hold now equals “whales.” That is, it treats my shadow variable as an original variable. However, if I add the curly-cues as such:
*set {photosub_hold} current_exhibit
THEN it works. and now photosubject_3=whales.

So I guess putting curly-cues around a variable turns it into a variables containing its content. Is that correct? And if so, could it just be that ChoiceScript IDE just doesn’t like that?

1 Like

No problem. maybe I would have helped more if I weren’t at work, but at least I served as a rubber duck :joy:

As for your now working code, I don’t know if CSIDE likes it or not, as I said I’ve never used it that way, but as long as it works for you I think you’ll be fine.
You can try doing the tests with the .bat tool or with vscode and the extension if cside doesn’t work

Quack quack. :slight_smile:
I am still having problem with the thing I posted in my first item: “Error: taking_photo line 56: Non-existent variable ‘0’”

I am one month into learning CS, so this is all new to me. Since you recommended it, I downloaded VSC and was able to get my book into it. When I select “Start Debugging” it says I need an extension (on a mac); when I agree it can’t find anything. Might I ask your advice on that as well?

1 Like

For sure.

You don’t have to use the debug function from VSC.

This is the extension you need. I know nothing about Macs but I think you can get it from the store in VSC. then open the main folder of your game and you can test it by right-clicking on the tab and choosing the test

The same extension has the instructions.

1 Like

Ah, fantastic. Thank you!

1 Like

Worth noting that you’re using the stuff that Dan prefaced with:

“Probably only programmers will appreciate these. Beware! They add complexity without adding much value.”

:slight_smile: Most of us, definitely including me, are non-programmers and have taken him at his word. But let me try to see if I can figure it out.

From the errors you’re getting, I’m assuming that current_learning is a string variable and history is numeric? (That’s why it fails without brackets – you’re taking a string, “History,” and trying to perform an arithmetic operation on it, like trying to *set first_name +5.)

Judging by the error message, what’s happening in your original post example is that Quicktest is reading this:

*set {current_learning} %+ology_change_mid

as an attempt to

*set 0 %+ology_change_mid

i.e. to adjust the variable named “0” by a certain amount, when of course what we want is to adjust the numeric variable named history instead:

*set history %+ology_change_mid

Can I check if there’s a point anywhere in the game where you

*set current_learning History

rather than

*set current_learning "History"

? Because it feels to me like that could be the source of the error. When you play through your WIP successfully, you’d be hitting places where you did the latter, but QT checks all possibilities and might be picking up on an instance of the former. If not, I’ll keep brainstorming. :slight_smile:

(Btw, because the fairmath “zero point” is 50 and fairmath can never take a variable to either 0 or 100, I believe it’s generally good practice to *create any variable that you’re going to add/subtract using fairmath operators, as 50 rather than 0. But that alone wouldn’t solve this particular problem.)

CSIDE modifies very little around CS, it largely just hands off your code to the interpreter. Short of it being on an out of date version, it’s typically unlikely that the behaviour will differ to running it elsewhere. That’s not to say it can’t ever, but I’d be shocked if this was related.

It sounds to me like this is a “quicktest cheat” issue. Quicktest doesn’t actually run your game line by line, it makes some checks and assumptions about the values in your variables that may not ultimately be possible in your final game.

Is the variable in question initialized to 0 when you create it? If so, what happens if you change it to a non zero value?

1 Like

@CJW @Havenstone Thank you both. You both gave me things to try. I figured the string variable/ numeric variable might be the source of the problem, but I think I found a different source of it.

First, In startup.txt I set:
*create current_learning "0"

Then, in chapter1, I assign it a value, such as:
*set current_learning "Biology"

In taking_photo.txt I use:

"Well, okay," you say, "but I'm not that into ${current_learning}." 
*set {current_learning} %+ology_change_mid

When I run it, it turns into:
“Well, okay,” you say, “but I’m not that into Biology.”
AND the variable Biology successfully increases in value.
However, QuickTest for some reason reads it as:
Well, okay," you say, “but I’m not that into 0.”
AND the variable 0 creates an error when it can not find it.
It thinks 'current_learning" is not a number but a string, and it is not recognizing for some reason the second step (when it changes from 0 to Biology).

Now that I know that, I will now try to create less elegant code to avoid this QuickTest error. Oh well - it was worth a shot. And I can’t tell you how much I appreciate all of your advice and support.

You could just *create the current_learning with the value of an actual numerical variable’s name. Or create a variable just for the sake of using it as the initial value, if your code would get confused otherwise.

1 Like

Sorry, I don’t follow. For the first approach, I thought I did that (that is, I created current_learning then set it to whatever the current value should be - which is always a numerical variable’s name, such as Biology). For the second, I am not grokking.

Less elegant might also be less confusing. :slight_smile: But a couple thoughts:

current_learning is a string, because you created it with something in quotes (even though what you put in quotes was a number).

And that’s good – if you want to use it with curly brackets like you were trying to, it needs to be a string, because your variable names are strings, not numbers.

You just need to create it with an actual variable name inside the string. Make it Biology or History by default – so *create current_learning "Biology" at the beginning instead of creating it as “0”. Presumably you don’t have any code that would actually say “I’m not that into 0,” because the player has to choose their current learning before the variable’s content gets displayed anywhere. So the fact that you create the variable as “Biology” rather than “0” won’t make any difference to the player experience.

But it will make a difference to QuickTest. QT is a quick-and-dirty check to make sure all possible values of the variable work, regardless of whether those values are actually attainable at the point being checked. This affects other things too, like multireplace:

Right now, the QuickTest of your game is finding one (theoretically) possible value of current_learning that wouldn’t work with your curly brackets, because it isn’t the name of any variable. It doesn’t matter if, by the time an actual playthrough reaches {current_learning} the player has already had to change the variable to something other than “0” – QT doesn’t know that.

If you just make sure that any variable you put into curly brackets never (from creation onward) has the chance to be anything other than the name of another variable…then your code should work as you’d intended while passing QT.

But if that explanation is too hard to parse, you might be well-served by trying the less elegant, less confusing code. :slight_smile:

3 Likes

@Havenstone Oh! That makes perfect sense. I get that.
Okay, so what I need to do - to insure all possible instances are valid to QT - is open that last file with an *if series that assigned the content of current_learning to newly created variable, and then ELEGENTLY use that new variable repeatedly throughout that doc. I’ll try that later and let you know!

If so I can get rid of this!

           *if current_learning="Anthropology"
              *set Anthropology %+ology_change_mid
          *if current_learning="Astronomy"
              *set Astronomy %+ology_change_mid
          *if current_learning="Biology"
              *set Biology %+ology_change_mid
          *if current_learning="Entomology"
              *set Entomology %+ology_change_mid
          *if current_learning="Geology"
              *set Geology %+ology_change_mid
          *if current_learning="Paleontology"
              *set Paleontology %+ology_change_mid
          *if current_learning="History"
              *set History %+ology_change_mid
1 Like