Scope of caller in new function object

Discussion and feedback on Construct 2

Post » Mon Dec 31, 2012 11:21 pm

Hey guys, evaluating Construct 2 for use in future projects, and I'm attempting to implement a version of the old Intellivision favorite, "Astrosmash!" in it. It's been surprisingly easy to do, and I'm having a blast, however I'm having trouble understanding what's going on in one particular spot, so I figured I'd ask here.

I have an ASTEROID sprite object.

Inside its onCreate callback it's calling a FUNCTION (of the new object type that was just added) goes ASTEROID -> Set effect "Set Color" parameter 1 to 255.

Now, I know I'm just referencing "ASTEROID" inside the function call, but it doesn't seem to affect the ASTEROID actually doing the calling. It does seem to work, however, after *another* ASTEROID is spawned.

Do I need to pass some sort of reference to the ASTEROID calling the function?

This is kind of frustrating, because this would be easy enough to figure out in a traditional language.

If I need to link to the project file, if this isn't clear enough, I can do that easy enough.

Much thanks, gang.
B
11
S
2
G
3
Posts: 7
Reputation: 2,444

Post » Tue Jan 01, 2013 1:34 am

Yeah, I really should have just posted a link to the .capx to begin with: http://dl.dropbox.com/u/6964418/astrosmash.capx :P

The "ASTEROID" is literally called Asteroid, and inside it's group in the Main Events file is a SetRandAstCol function. If there's a more "C2" way of doing what I'm trying to do (set the caller to a random color), I'm interested.

Thanks in adavance!
B
11
S
2
G
3
Posts: 7
Reputation: 2,444

Post » Tue Jan 01, 2013 1:57 am

astrosmash_edit.capx (r114)

You say "the asteroid that's doing the calling" but an object doesn't actually call a function. Even though you're calling the function in the 'on created' trigger you still need to pass the asteroid's UID. Which you're doing in the capx, so then you just need to pick the asteroid with that UID in the function.

That leads to another problem. You can't pick a newly created object until the next top-level event. There are threads explaining why that I don't want to search for right now but basically because you're calling the function from the 'on created' trigger you can't pick that newly created asteroid yet. The work around for that is the 'Wait 0 seconds' action which makes it postpone calling the function until the end of the event sheet, by which time the asteroid object is properly created and can be picked normally.

I hope that makes sense.
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Tue Jan 01, 2013 2:15 am

It does, and that's very helpful. I probably wouldn't have figured out the "wait 0 seconds" hack on my own. :P I forgot that I was just starting to experiment with passing the UID when I wrote this, so at least I was on the right track. ;D

I really didn't know how to work with "picking", but I understand it now, and have started to get it working properly.

Thank you! :)
B
11
S
2
G
3
Posts: 7
Reputation: 2,444


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 1 guest