Scope of caller in new function object

0 favourites
  • 4 posts
From the Asset Store
This pack has 1696 individual .wav and mp3 files that have everything to do with bingo.
  • 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.

  • Yeah, I really should have just posted a link to the .capx to begin with: 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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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! :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)