Function Names

For questions about using Classic.

Post » Sun Oct 24, 2010 2:47 pm

Functions
When I add a function parameter then use that parameter for an event, it doesn't register.
Something like:

Button Clicked -> Add Paramter 2 (an integer)
if Function.Param(1) == 2 -> do something

it doesn't do something..
However, if I do this:

Button Clicked -> Add Paramter "something" (a string)
if Function.Param(1) == "something" -> do something

it works! :)

So is this a bug or am i doing something wrong
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Sun Oct 24, 2010 2:52 pm

Can you post a screen of your actions, or copy as text this part of event list? Or maybe cap.
B
19
S
6
G
4
Posts: 171
Reputation: 2,507

Post » Sun Oct 24, 2010 5:23 pm

[quote="hero_bash":1nrl1d2m]Functions
When I add a function parameter then use that parameter for an event, it doesn't register.
Something like:

Button Clicked -> Add Paramter 2 (an integer)
if Function.Param(1) == 2 -> do something

it doesn't do something..
However, if I do this:

Button Clicked -> Add Paramter "something" (a string)
if Function.Param(1) == "something" -> do something

it works! :)

So is this a bug or am i doing something wrong[/quote:1nrl1d2m]
You shouldn't rely on a function parameter being accessible through events. You don't know how they are stored internally, converted, etc. Those parameters are always accessible within a function and you can rely on that. But for a structure like the one of your example you have global and private variables.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Oct 24, 2010 7:42 pm

Yea. I think it was bad practice that I was trying to compare the parameter using system function and as an event..hmm, maybe I should try assigning the parameter to a global variable and then use it for an event condition.
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Mon Oct 25, 2010 3:27 am

[quote="hero_bash":25xuhyac]...I was trying to compare the parameter using system function and as an event..[/quote:25xuhyac]
Not to confuse you, but this is possible ...as long as it is done within the function declaration. For example:
+On function "test"
++function.param(1) equal to 2
->Set text to "yes it works"

+timer is equal to 5000
->add parameter 2
->call function test

Assuming there's a textbox and a function object in the layout, this will set the text to "yes it works" after 5 seconds have passed.

This means, if you want some kind of a central point to manage a menu or something like that, you could set up a function that will test for all possible values:

[code:25xuhyac]on function "selector"
function.param(1) equal to 1
->do menu 1 option
else
function.param(1) equal to 2
->do menu 2 option
else
function.param(1) equal to 3
->do menu 3 option

on left clicked on red sprite
->add parameter 1
call function "selector"
on left clicked on green sprite
->add parameter 2
call function "selector"
on left clicked on blue sprite
->add parameter 3
call function "selector"[/code:25xuhyac]
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest