Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   Questions and Comments (http://www.alice.org/community/forumdisplay.php?f=9)
-   -   Problems with variables in Alice 2.2 (http://www.alice.org/community/showthread.php?t=9563)

CaptainLizard 10-17-2012 10:07 AM

Problems with variables in Alice 2.2
 
1 Attachment(s)
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 05:59 PM

bump

x2495iiii 10-21-2012 08:19 PM

1 Attachment(s)
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 09: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 [I]hour of AM or PM[/I] and the [I]minute of hour[/I] 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 09:51 PM

1 Attachment(s)
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 10: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.


All times are GMT -5. The time now is 07:44 PM.

Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.