Computer Science Canada

Variable has no value

Author:  asdfasdf123 [ Thu Dec 18, 2014 11:51 am ]
Post subject:  Variable has no value

What is it you are trying to achieve?
I'm working on a slot machine that adds $500 to the payout when there are 3 of the same symbol in a row.


What is the problem you are having?
It works most of the time, but every now and then, the program stops and it says that a variable "has no value".


Describe what you have tried to solve this problem
I added an "else" to the "if" statement that I used to give out the $500, but it didn't work.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
middle2, right2, and left2 are the values of the randomly generated numbers used to display the symbols on each reel, multi is the amount of money the user placed in the slot machine x2, and prize should be self-explanatory.

Turing:


if middle2 = right2 and left2 = middle2 then
                    prize := Rand.Int (0, multi) + 500
                    put "Congratulations! You win an extra $500!"
                else
                    prize := Rand.Int (0, multi)
                end if



Please specify what version of Turing you are using
4.1 1.0.1

Author:  Insectoid [ Thu Dec 18, 2014 2:24 pm ]
Post subject:  RE:Variable has no value

'Variable has no value' means you're trying to check the value of a variable that hasn't been assigned.

code:

int a;
if a = 1 then
    put "This will crash immediately."
end if


Look through your code. Every time you compare a variable, check to make sure you've actually assigned a value to it.

Author:  asdfasdf123 [ Fri Dec 19, 2014 8:34 am ]
Post subject:  Re: Variable has no value

They're all random integers.

Author:  Insectoid [ Fri Dec 19, 2014 10:08 am ]
Post subject:  RE:Variable has no value

Are you sure? Could it be a different variable entirely that's causing the problem? It's impossible for me to tell without seeing more of your code.

Author:  asdfasdf123 [ Fri Dec 19, 2014 11:41 am ]
Post subject:  Re: Variable has no value

I haven't seen it since I edited the code, but here's the program (it's 1SlotMachine.t, but it takes the entire folder to run and you have to run it from 1MainMenu.t):

Author:  Insectoid [ Fri Dec 19, 2014 1:48 pm ]
Post subject:  RE:Variable has no value

You've got way too many files for me to bother going through it all, but I played with it for a while and was unable to reproduce the bug.

Author:  asdfasdf123 [ Fri Dec 19, 2014 2:03 pm ]
Post subject:  Re: RE:Variable has no value

Insectoid @ Fri Dec 19, 2014 1:48 pm wrote:
You've got way too many files for me to bother going through it all

Only 2 of the files do anything besides display images, so it doesn't matter if you didn't go through them.


: