function, remember picked for expressions return values

New releases and general discussions.

Post » Sun Jan 18, 2009 10:48 am

Not sure if its me doing something wrong as i'm new to functions.

I have multiple instances of an object, each with a private value of either blue box or red box.

When you click on one of these instances i want to create another object based on what type of private value it has which i've clicked on.

I thought an elegant method would be to do -

on object clicked > create object by name (funtion. return myfuntion)

on funtion(myfunction)
+instance priavate variable(object type)= "blue box" > return function (BlueBoxSprite1)

on funtion(myfunction)
+instance priavate variable(object type)= "red box" > return function (RedBoxSprite1)

So the function compares the private value and if its a blue box it returns the blue blue box sprites name, and same for if its red.

but i think the problem is when calling return functions in an expression there is no option to remember or forget picked objects, like you can do if it's just an action "call function".

Is this right or have i got things wrong?

Thanks.
B
37
S
19
G
18
Posts: 615
Reputation: 10,235

Post » Sun Jan 18, 2009 2:39 pm

why even use functions for this?

>on object clicked
(subevent) +('obj type')=blue box >>> spawn blue box
(subevent) +('obj type')=red box >>> spawn red box


now you have one event instead of three.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Sun Jan 18, 2009 3:35 pm

I simplified my problem down as an example.

What am actually doing is much more complicated but it boils down to what i posted.

Thanks.
B
37
S
19
G
18
Posts: 615
Reputation: 10,235

Post » Sun Jan 18, 2009 6:05 pm

Why not store the actual name of the sprite to spawn in the private variable?

Ie. Create object by name: Object('name_to_create')
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 1 guest