This site requires JavaScript, please enable it in your browser!
Greenfoot back
Psychpsyo
Psychpsyo wrote ...

2016/4/3

Add Objects depending on variable

Psychpsyo Psychpsyo

2016/4/3

#
Hello. I want to know if there is a way to add a different object depending on the value of a variable? So if the variable is 1 add Object1, if it's 2 add Object2 and so on... Is it possible WITHOUT writing an if statement for every single object?
Super_Hippo Super_Hippo

2016/4/3

#
This is an example of doing it.
Actor a[] = {new Actor0(), new Actor1(), new Actor2()};

// when you want to add one
/*getWorld().*/addObject(a[theVariable], 100, 200);
Psychpsyo Psychpsyo

2016/4/3

#
Thanks! That is exactly what I needed.
You need to login to post a reply.