Computer Science Canada error message help |
Author: | sammi7 [ Thu Dec 08, 2011 6:07 pm ] | ||
Post subject: | error message help | ||
What is it you are trying to achieve? <im trying to make the game Snake and add in bonus food to make the snake grow more What is the problem you are having? <whenever i try and eat the bonus food(blue) it says variable has no value and i dont know how to fix it.> Describe what you have tried to solve this problem <Answer Here> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <4.1> |
Author: | Tony [ Thu Dec 08, 2011 6:11 pm ] | ||
Post subject: | Re: error message help | ||
sammi7 @ Thu Dec 08, 2011 6:07 pm wrote: it says variable has no value and i dont know how to fix it.
You should assign a value to that variable. A more helpful question -- what do you think the value of the variable is, when it's accessed? Well, it turns out that it didn't have any value assigned before use. E.g.
What should the answer be? Obviously that doesn't make sense until variable actually holds some value. Trace back through your program to see what's going on. |
Author: | sammi7 [ Thu Dec 08, 2011 6:53 pm ] |
Post subject: | RE:error message help |
but i already declared it at the top. and when i tried taking out the part about the whatdotclour for the bonus food it worked....Why does it only happen when i add the bonus food check in? |
Author: | Tony [ Thu Dec 08, 2011 7:00 pm ] |
Post subject: | RE:error message help |
sure, I also declared the variable called "value" at the top of my example. What's the output? |
Author: | sammi7 [ Thu Dec 08, 2011 7:07 pm ] |
Post subject: | RE:error message help |
ya i know but it works with the original red food....thats what i dont understand.....How do i make it work with both foods? |
Author: | Tony [ Thu Dec 08, 2011 7:19 pm ] |
Post subject: | RE:error message help |
well, you are doing something to grow the snake with regular food (assigning values to variables) that you are not doing to bonus food (variable doesn't get assigned a value before it is used). Though looking at your implementation, it could be that regular food works just by a coincidence. |