Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
I feel trapped - For each with methods? Print variable?
Old
docsaintly
Guest
 
Status:
Posts: n/a
Cool I feel trapped - For each with methods? Print variable? - 09-28-2009, 10:08 PM

Hello all, I'm a somewhat experienced programmer taking an Alice & Java course to satisfy degree requirements, I feel like I'm trapped inside a box.

I'm trying to do some things that are pretty easy by programming standards, but Alice is being very limiting. I'd like to:

- Show a variable as text on the screen.
I have tried this. I have it set up so that when the user clicks on an object it will increment the variable, i have watched the variable and it indeed increments, but when I have something say it or even print it at the end of the scene, it always reports its initialized value (1).

- Have each object within a list perform a method (and not have to do all the actions within the for all area)

- Copy a method from one object to another.
This is not mandatory, but would be nice. In regular programming I would just copy the code from one class to another.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 09-29-2009, 10:04 AM

Granted, Alice isn't as versatile as some other programming languages, but believe it or not Alice can do all of those things you just asked.

-setting a variable as text: this can be done, and I've done it plenty of times. The only thing that slightly annoys me is the fact that the text-version of the variable has a decimal point and a zero (a double variable). I really don't know why it isn't working for you, but you could always post your world and let me take a look at it.

-having each object in a list perform a method: you could make an index variable for your object list, then have the nth item on the list do something, then have the index variable increment and repeat. This way, you can have one object from the list (your choice based on index) do one method.

-copying a method: This is easy. Just take all the code you want, put it all in a "do in order" area, then just drag the do in order to the clipboard in the upper-right, then drag the clipboard item down to the class you'd like to use it in.
You'll have to change the names of the relevant objects, but the method nature and order will be the same.
   
Reply With Quote
Old
docsaintly
Guest
 
Status:
Posts: n/a
Default 09-29-2009, 10:21 PM

Thanks for the response. After another hour last night i was able to find most the things you talked about. The thing i'm stuck on now is an event. THe point of the game is that I make a list of objects and the user has to try to click on each one (an anvil) as it moves past the screen. I can't seem to drag and drop any sort of item from the list to the events area to say that if the user clicks on any item of Anvils, that it should increment a counter. Ideally i'd like it if I could make a parallel list of booleans to check to see if each has been clicked, but nothing comes to mind. Any ideas are appreciated. Thanks
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 09-29-2009, 10:54 PM

For that setup you'd need either a separate event for each item (click the add event button, then choose when an object is clicked event and change the object to the anvil) or you could use a click check method (add the "when an object is clicked" event, but have it call a method called clickCheck and pass the object under the mouse cursor as a parameter. Then, from inside clickCheck, use if/else ifs to check which item was clicked)

Last edited by x2495iiii; 10-25-2009 at 01:16 AM.
   
Reply With Quote
Thanks
Old
docsaintly
Guest
 
Status:
Posts: n/a
Default Thanks - 09-29-2009, 11:03 PM

Thanks for the quick reply. This is what I was afraid of. It's not a big deal to me, but the whole focus of the chapter was to use lists to perform repetitive tasks that are the same for an entire group of objects. Oh well, as long as there's no way to do it without making an event for each object or a long if statement, i don't mind doing it that way.
   
Reply With Quote
Old
BenMcLean
Guest
 
Status:
Posts: n/a
Cool 09-30-2009, 01:50 PM

Quote:
Originally Posted by docsaintly View Post
I'm trying to do some things that are pretty easy by programming standards, but Alice is being very limiting.
The Cat only grinned when it saw Alice. It looked good-natured, she thought: still it had VERY long claws and a great many teeth, so she felt that it ought to be treated with respect.

'Cheshire Puss,' she began, rather timidly, as she did not at all know whether it would like the name: however, it only grinned a little wider. 'Come, it's pleased so far,' thought Alice, and she went on. 'Would you tell me, please, which way I ought to go from here?'

'That depends a good deal on where you want to get to,' said the Cat.

'I don't much care where—' said Alice.

'Then it doesn't matter which way you go,' said the Cat.

'—so long as I get SOMEWHERE,' Alice added as an explanation.

'Oh, you're sure to do that,' said the Cat, 'if you only walk long enough.'

Alice felt that this could not be denied, so she tried another question. 'What sort of people live about here?'

'In THAT direction,' the Cat said, waving its right paw round, 'lives a Hatter: and in THAT direction,' waving the other paw, 'lives a March Hare. Visit either you like: they're both mad.'

'But I don't want to go among mad people,' Alice remarked.

'Oh, you can't help that,' said the Cat: 'we're all mad here. I'm mad. You're mad.'

'How do you know I'm mad?' said Alice.

'You must be,' said the Cat, 'or you wouldn't have come here.'


- Lewis Caroll, Alice's Adventures in Wonderland
   
Reply With Quote
Reply

Tags
for all, method, text, variable

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



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