Input Number Variable Not Changing


#1

Hi, sorry to ask this question. I am new to ChoiceScript. I searched for answers all night long and for most of this morning, and I just can’t seem to find them.

I’m creating a number variable, then asking the player to enter a number. I’m attempting to have the player change the value of the number variable. But after the player enters the number, the variable does not seem to change.

If anyone can help me understand why the user entered number is not taking, I would greatly appreciate it.

Thanks very much in advance. I am using Firefox as my browser on a PC.

Here is my code in startup.txt

*comment test game

*title Test Game 1
*author Anonymous
*scene_list
  startup

*create var 0

The first number variable is currently ${var}

Please input a new number between 0 and 100.

*input_number var 0 100
 
Thank you. The first variable is now ${var}

*finish

#2

Ok kind of odd. I couldn’t find anything wrong with your code so I pasted it into a startup file and ran it. It worked first time. Both in firefox and chrome. Have you made any changes to the standard js files that might be causing conflicts?


#3

No, I haven’t made any changes to any other files. I am using the ChoiceScript source from

as instructed. I did delete the variables.txt from web>mygame>scenes folder, but I don’t believe I’ve opened or altered any other files in any other folder.

I am able to get the user to change a text variable, and I am able to add numbers to the number variable, but I still don’t understand how to get the player entered number to stick.

I appreciate your help, thank you.


#4

Sorry I am kind of at a loss. The only suggestions I have left are try changing the variable name from var to something unique. It’s possible there is a conflict with one of the example codes in another text file. And a slightly desperate, did you close the browser after altering the code rather than just refreshing it? I’ll be back if something more useful occurs…


#5

Whenever I make changes to choicescript, I always close the demo down and re-open it fresh. This is because the code doesn’t always update with a simple refresh of the browser. Especially when adding/ changing default variables.

As for your code, it looks fine and the variable name shouldn’t cause any problems… My guess is re-opening the demo should solve your problem.


#6

No luck so far.

I changed the variable identifier from “var” to “coins” using an example provided in the tutorial. I shut down and restarted the browser, and even restarted the computer, and still the user entered number will not stick.

I changed the code a bit to check if I can enter a text variable and to see if I can alter the number variable in another way. Both tests work fine. I can enter a text variable and it will stick. I can alter the “coins” variable by saying *set coins +10. But still the user entered *input_number coins 0 100 does not seem to change the variable I created in *create coins 0

to test the game, I am going to
dfabulich-choicescript-5016efa > web
and then opening the index html file in Firefox by right clicking on it.

To write the game, I am going to
dfabulich-choicescript-5016efa > web > mygame > scenes
and rewriting the startup.txt and choicescript_stats.txt files. I am careful to use UTF-8 encoding when saving the txt file.

Random guesses:
Do I need a separate file in my scenes folder called "variables.txt?"
Does the problem have anything to do with the *set command? I have tried adding it, but it seems not to solve the issue.
Are my indentations right?
Might there be ome outdated files included in the original first game tutorial that might be conflicting with some other, newer files?

My most recent test code is below:

*comment I am unable to make the user defined number variable stick
*comment though the text changing works, and the number variable
*comment can be added to with a "set" command

*title Test Game 1
*author Anonymous
*scene_list
  startup

*create coins 0
*create name "Unknown"

The number variable is currently ${coins}.

The name variable is currently ${name}.

Please input a new number between 0 and 100.

*input_number coins 0 100

Please input a name.

*input_text name

Thank you.

The number variable is now ${coins}

The name variable is now ${name}

Try to add 10 to the number variable?

*choice
  #Yes
    *set coins +10

    Number variable is now ${coins}
    *finish

  #No
    Number variable is now ${coins}
    *finish

*finish

#7

I don’t know what the problem actually is, but I know you are looking in the wrong place bud. When I pasted it into a startup file and ran it there was no problem. Which means there is nothing wrong with the code its self. Some outside factor is causing the problem, but no matter how much you tweak already working code it won’t make a difference. Although a random thought occurs. The only text document in the folder when I ran it was startup. I didn’t bother making anything else for a single test. Maybe you should try taking everything out of the folder except startup and seeing how it does? That would at least tell you if it was a conflict of some kind.


#8

You’re not crazy! There was an actual bug in *input_number in dfabulich-choicescript-5016efa. I just fixed it in the latest version of ChoiceScript up on github, 0cdb371.


#9

Wow! Thank you, I really appreciate that. Thanks for the prompt reply and the fix.

I’m glad I’m not crazy! I was beginning to wonder… :smile: