Alice Community  

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

Reply
 
Thread Tools Display Modes
Skip objects in a List?
Old
crazeelax608
Guest
 
Status:
Posts: n/a
Default Skip objects in a List? - 10-21-2010, 07:04 PM

For example, if I want to make the first object in the list jump, then the third object, then the fifth, etc.

Also, this code should work for a list of any size, whether there be 5 objects or 105 objects in the list.

Thanks for the help.
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 976
Join Date: Sep 2009
Location: United States
Default 10-21-2010, 08:42 PM

I haven't tried, but couldn't you make a method with a number parameter "x", and then in the method do a code for "(x)th item of (list), jump", and then after that drag in the same method that you are working on and drop it below that statement that I just told you to write, and for the parameter do "(x) + 2". Now it will redo the method, except this time the "x" parameter will be the next odd number.

Now, this will keep going forever in a recursive loop, so you have to put all the contents of the entire method into an if/else statement, and say "if(x < (totalNumberOfObjectsInList))". Of course, you would substitute that "totalNumberOfObjectsInList" thing for the actual number of the items you have in the list, so that once the "x" parameter goes above that number, it will stop recalling the same method. It would be very easy if there was a function to tell you the total number of objects in the list, that way there could be any number and it would still work. If there is no such a function, you can actually create your own.

First, try what I have said, and if there is no pre-written function to give the number of objects in the list, and you don't know how to create that function, then I will tell you, just ask.

If you absolutely are lost with what I just told you, then I guess I can upload an image, or better yet just create a program with that example.


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
   
Reply With Quote
Old
crazeelax608
Guest
 
Status:
Posts: n/a
Default 10-21-2010, 09:04 PM

Ok, I understand your second part about the if/else and yes, there is a built-in function for size of list.

Now, I created the parameter X in the method, but where am I passing (X+2) as a parameter?
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 976
Join Date: Sep 2009
Location: United States
Default 10-21-2010, 09:10 PM

Quote:
Originally Posted by crazeelax608 View Post
Now, I created the parameter X in the method, but where am I passing (X+2) as a parameter?
The parameter is always asked for when you call upon the method. Inside the if/else I asked you to recall the same method, which is using recursion. When you recall this method, it should ask you for the parameter again, so just drag "x" in there, then click that and go to "Math", then "add" and "2".


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
   
Reply With Quote
Old
crazeelax608
Guest
 
Status:
Posts: n/a
Default 10-21-2010, 09:15 PM

Nevermind I got it, thanks.
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 976
Join Date: Sep 2009
Location: United States
Default 10-21-2010, 09:19 PM

Did it work though? Is every other object jumping?

EDIT: Yay, 800th post


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
   
Reply With Quote
Reply

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 ©2023, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.