Getting Even/odd List ID

Balmut

  • *
  • Posts: 21
Say I have a list like so:

0: Cat
1: Dog
2: Mouse

Is there a way of only getting the Even or odd ones?

I want something like:
If List ID is Odd do something

Yeah, have a number attribute which starts at 1. Use the "get item #[0] from list" block with the 0 replaced with the number attribute. Then change the attribute by 2, run the list block again and repeat. Do the same for even ones just start at 2.

Hectate

  • *
  • Posts: 4643
Another option; you can use the Modulo (%) operator to determine if there's a remainder when dividing by two. If a number is evenly divisible by 2, it's even. If not, it's odd.

Set Index to 0
For Each Item in MyList:
:If (Index % 2) //Odd numbers return a value which equates to TRUE
:- Do What You Want With Odd Items
:Else //even numbers return a 0, which equates to FALSE
:- Do What You Want With Even Items
:Increment Index by 1
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Balmut

  • *
  • Posts: 21
Oooo, that might be a better option for me. In the stencyl math blocks, it's the " remainder of x / y" block I want right?

Nathbo

  • Posts: 388
yes reminder of x/2 = 0
Visit my Facebook page
http://www.facebook.com/NathboGames

Twitter
@NathboGames