PDA

View Full Version : Problems with variables in Alice 2.2


CaptainLizard
10-17-2012, 11:07 AM
So i have a simple assignment in class to make a combination for a lock and make it open when you input the combination correctly. But the problem I seem to be having is that my variables will not change at all. It's as if the variables don't get called at all. Any help would be appreciated! Attached is what I have of the program.

CaptainLizard
10-21-2012, 06:59 PM
bump

x2495iiii
10-21-2012, 09:19 PM
The world seems to work fine for me, and the variables change just fine as well.

Right click the variable at the top of the method, and click "watch this variable" to see it change in real time.

The only problem I see with the world is the fact that there's no mechanic to make the dial go specifically to the number specified, meaning that the user has to think of differences instead of values. I added one which makes the lock turn to the number entered, so that each number can be tried sequentially instead of entering 1 or -1 in every time.

The other problem is that there's no indication that the user has entered the correct number. You should add something like making the lock move or say "click" when the right number is entered.

CaptainLizard
10-21-2012, 10:26 PM
hmm That's odd because when I made the world, I watched every variable change and it worked. But every time I've tried to run it or when my teacher tried to show it to the class, it hasn't worked. Which also implies that he had it working whenever he was grading it. But as of late, I can't get variables to work in any of my assignments, including this one that I'm redoing for the Chapter 7 exercise, like the Clock Exercise in Chapter 7 (Exercise 10), which asks you use the hour of AM or PM and the minute of hour functions to set the values for the hour and minute hands. I'll post that world when I complete the required methods.
Thanks for the help though :D

EDIT: Again, I loaded your example, and the variables don't change. I've entered the whole combination and even some random numbers to try to get something to change but I get nothing. -__-

x2495iiii
10-21-2012, 10:51 PM
If the variables aren't working, it's possible that it's because of a bug which makes local (method-level) variables go unrecognized.

Just change all the variables to global (world-level) ones and change the methods to use them accordingly. I posted another example with all the global variables made, but you'll need to make the methods use them yourself.

As for the way the numbers were made, I just made an extra variable (moveNumber) which subtracts itself from the number the user enters, leaving only the amount that the dial needs to move in order to move from its current position to the requested one.

CaptainLizard
10-21-2012, 11:37 PM
THANK YOU SO MUCH!!
I figured it was a glitch, but I didn't know how to create global variables until I found them in the properties! Also, I checked back with the book, turns out we don't learn variables until Chapter 10! If i wasn't ahead already, I am now! :D Thanks again for the help. This problem has been bugging me for awhile.