0 Favourites

Compare Instance Variable Problem

  • Hello! I'm having issues with a series of events that check an Instance Variable. Basically, for an endless runner type of game, I'm spawning objects at random locations along a path so long as that object isn't already on screen.

    To do this, I'm checking an Instance Variable named "Active" for an object, and if the variable is 0 (which is its default setting), spawning the object and then setting its variable to 1. When the object is later destroyed, its variable is set back to 0. Here's what the event sheet looks like at the moment:

    <img src="http://i216.photobucket.com/albums/cc212/darkstorne/Long_zpsa18dfbb2.png" border="0" />

    It doesn't work. None of the background objects (that require Instance Variable checking) spawn. The foreground objects work perfectly.

    Disabling this didn't change anything. Still no background objects spawned:

    <img src="http://i216.photobucket.com/albums/cc212/darkstorne/Short1_zpsbfc3063e.png" border="0" />

    But disabling this does allow the background objects to spawn. However, it spawns loads of them, since there's nothing to tell C2 to stop spawning the objects:

    <img src="http://i216.photobucket.com/albums/cc212/darkstorne/Short2_zps8e7c9675.png" border="0" />

    Finally worth noting - I had originally tried setting the events up like this (using a sub event), but this doesn't spawn any background objects either:

    <img src="http://i216.photobucket.com/albums/cc212/darkstorne/Short3_zpse868e47a.png" border="0" />

    Sorry for using so many images, but I wanted to be as thorough as possible so you know what I've tried <img src="smileys/smiley1.gif" border="0" align="middle" /> Any idea where I'm going wrong?

    Many thanks for reading <img src="smileys/smiley12.gif" border="0" align="middle" />

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • It`s pretty hard to say what is going on without seeing the whole .capx, as there is lots more going on in your project than those comparisons :-)

  • -Silver-   Just guessing here, but if you're destroying the object, and then setting isActive to 0, you're not actually applying the variable to anything (because the object doesn't exist). So the only object that will have isActive = 0 is the one you've initially placed in your layout until it becomes active.

    Not sure if this would work for you, but if you only ever want to have one instance of an object on screen at a time, could you not just keep reusing the same object? So instead of destroying the object, set isActive to 0 when it moves off the left side of the screen. Then when it's time to use it again, just move it to the right side?

    Not sure if any of that makes any sense in your situation, though ;)

  • vee41 - There is much more going on, but not in relation to these Objects. That's all there is to them. Other than the part where they get destroyed when they move off to the left of the screen.

    @rogueNoodle - I'm setting the variable to 0 first, and then destroying it. Sorry, I should have made that part clearer. Though, even if that part was wrong, they'd need to be created before they can be destroyed anyway, so they'd at least be spawned once before the variable can be set to 1.

    You're right about the second part though! I'll try having C2 simply move them, instead of creating a new object and destroying it every time. It just means there will be slightly more object bloat (and each object has a bullet behaviour being acted on every tick too). I'll see how it works though <img src="smileys/smiley1.gif" border="0" align="middle" />

    Still leaves me confused about the above events, because I genuinely can't understand why they wouldn't work.

  • vee41 - There is much more going on, but not in relation to these Objects. That's all there is to them. Other than the part where they get destroyed when they move off to the left of the screen.

    Things like what objects you have in the layout, initial values and stuff actually impact how one would solve this problem, it's hard to say without the view to whole project.

  • vee41 - As I said in the OP, 0 is the initial value, and it isn't changed to 1 until it's spawned (then back to zero before destroying it). Other objects in the layout won't impact the spawning of new, unrelated objects. Other than the destroy section, I've posted and screenshooted everything related to it.

    @rogueNoodle - Worked perfectly, thanks! <img src="smileys/smiley4.gif" border="0" align="middle" /> Events now look like this, and there's no noticeable performance impact:

    <img src="http://i216.photobucket.com/albums/cc212/darkstorne/Short4_zps4c725713.png" border="0" />

    If anyone knows why the original event setup might not have been working, I'd love to hear from you. It's great having a solution, but I'm still not sure where I was going wrong before <img src="smileys/smiley12.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
[Plugin] instance bank2
85 18,367
rexrainbow's avatar
rexrainbow
Unread hot topic
98 7,593
norum82's avatar
norum82
Unread hot topic
87 5,374
facecjf's avatar
facecjf