Why doesn't this function call work as expected?

Get help using Construct 2

Post » Wed Nov 13, 2013 9:09 am

Hi. I'm at a loss here. I have used functions in a similar way before so I'm not sure if I'm missing something here or doing something completely wrong or is this a bug.
Maybe it just needs some fresh eyes.

So, version 1 works, the sprite is spawned as expected.
Version 2 doesn't work, the object is spawned somewhere outside the canvas (0,0 perhaps).



Any ideas?
B
16
S
7
G
1
Posts: 161
Reputation: 3,131

Post » Wed Nov 13, 2013 9:17 am

It's cause you use Wait 0.02 with a function parameter/local variable.

At the moment your create triggers the function has been already over and the function param isnt given any more. The only ways I know are to use global or instance variables.

Eg. grand Starry 2 instance variables(functionX, functionY)
+ repeat 7 times
-- create object starry
-- set Stary.functionX to Funtion.Param(0)
-- set Stary.functionY to Funtion.Param(1)
-- Wait 0,02*loopindex
-- Set position starry(starry.functionX, starry.functionY)Darklinki2013-11-13 09:18:17
B
15
S
6
G
6
Posts: 512
Reputation: 5,555

Post » Wed Nov 13, 2013 9:56 am

Genius! I would never have thought of that. Still, I thought function parameters are passed immediately no matter what and stay there, as in normal programming.

I'll use variables to get around this, thanks!
B
16
S
7
G
1
Posts: 161
Reputation: 3,131


Return to How do I....?

Who is online

Users browsing this forum: koops and 7 guests