Hidden features #7: Function expressions

Post your own tutorials, guides and demos.

Post » Tue Mar 10, 2009 2:21 pm

Using the Function object, you can use any expression name and have it call a function. This means you can make Function.SomeExpression return whatever you like, and you can pass parameters to it too.

The .cap file attached shows an example of this (made in 0.98.9).
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue Mar 10, 2009 2:55 pm

Wow.. even I'd forgotten that one.. That'll make a lot of things quite a bit simpler. Do you want to do a #8 on conditionals by the way, or should I?
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Tue Mar 10, 2009 3:07 pm

Go for it.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue Mar 10, 2009 3:29 pm

Holy crap, that's awesome. :) I didn't even know that existed.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Tue Mar 10, 2009 7:55 pm

Nice :). I remember this mentioned back in the day but I've only just recently started using the Function object so I'd forgotten all about it.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Mar 11, 2009 1:26 am

ah..thaaat's how you do parameters..thanks!
B
2
S
1
G
3
Posts: 39
Reputation: 1,078

Post » Wed Mar 11, 2009 2:04 am

Wow, that is so much nicer than adding the parameters in the previous events. Nice!
B
2
S
2
G
4
Posts: 136
Reputation: 1,722

Post » Wed Mar 11, 2009 10:10 pm

And I was using "Add parameter" methods.... Very useful. :D
B
2
G
3
Posts: 75
Reputation: 1,000

Post » Thu Mar 12, 2009 9:06 pm

Can you make default parameter values?
B
4
G
6
Posts: 32
Reputation: 1,514

Post » Fri Mar 13, 2009 12:02 am

No, that's not currently supported (but the Param expression returns 0 for any parameters that are not provided).
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Next

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests