Create Object and UID/IID's

0 favourites
  • 11 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • When using create object, how does one get the new instance's UID and IID back to store for later? Couldn't find any direct answer to this in manual or forums so far. Also, what is the difference between 'create object' and 'spawn object?'

  • The spawn action is an object action, the create object is a system action.

    The consequence of this design, is that if you call the spawn action each picked object will spawn something

    The second difference is that the spawn creates an object at the position of the calling object.

    In short, spawn is equivalent to:

    foreach object -> create object at object.X, object.Y

    As far as retreiving UIDs, you shoudl be able to do it like that:

    -> Create/Spawn object

    -> set variable to object.UID

    For IIDs I don't know exactly when IIDs are assigned and/or reevaluated. But usually, since there shouldn't be any "hole" in the IIDs the one attributed to the newly created object should be equal to object.Count. (ie: if you have 3 objects they probably have the IID 0,1,2 so the next one will be 3)

    But you shouldn't rely too much on IIDs, I don't exactly know when they are assigned or recalculated, and with so much imprecision you really should use your own indexing (with your own instance variable), and C2 could change their way of doing things. IID are good for temporary uses or when the state of instances don't change.

    When there's creation/destruction involved, you're better off handling things yourself or using UIDs.

  • Ok, so if I had several instances of an object, and I ran a spawn object, each instance would spawn a new object. But using create object, I would get just the one straight from the system? That makes sense.

    Quote/

    As far as retreiving UIDs, you shoudl be able to do it like that:

    -> Create/Spawn object

    -> set variable to object.UID

    /quote

    So how do I reference the new instance I just created, instead of another that may already be in existence? IE, I'm randomly generating a solar system, with a random number of planets. My random number generator comes up with five, so five planets are created. A few ticks later, I may need to update each individual planet's orbital positions and other data. In other languages/utilities, the creating function would return a pointer, or the equivalent of each planet's instances UID that could be stored and referenced later to get at instance-specific data. That's what I'm after.

    This will become very important as I progress in my project, since there will be a great deal of procedural generation going on.

    Thank you for your help so far!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So how do I reference the new instance I just created, instead of another that may already be in existence?

    When you create an object, it is automatically picked so you can store it's UID to array, other object or where ever you wish to reference it later on.

    I recommend you learn about picking which is really powerful tool in C2: C2 FAQ

    It would allow you to neatly accomplish things like:

    Pick all planets

    Solarsystem = 'new system'

    .. set variables

  • Thank you, I will check that FAQ.

    Another, minor thing: I cannot seem to make local variables. The manual says that they are created under events on the event sheet. Right clicking in the root (blank area) of the sheet gives the option to create a global, which works fine for me, but right clicking anywhere else give no options for variable creation. I am just wanting a couple local variables for number crunching in a function...

  • Another, minor thing: I cannot seem to make local variables. The manual says that they are created under events on the event sheet. Right clicking in the root (blank area) of the sheet gives the option to create a global, which works fine for me, but right clicking anywhere else give no options for variable creation. I am just wanting a couple local variables for number crunching in a function...

    You can just create a global variable and drag it inside the scope you wish to use it in, it becomes local variable. I recall V is quick key for creating variables, that works too.

  • Hey, that's slick! Thanks! Why isn't that in the manual under variables???

  • Hmmm, more problems. I've made my variables I intend to use inside my function local by dragging them into the area just below the part in the event sheet that has my function object name followed by the function's name in quotes. On my screen its a blank, light purple colored area. This made the variables local and they would seem to be part of the function. When I try to calculate something using them in a system->set (variable) to blahblah event, C2 tells me that my local variables(whichever one it encounters first) are an unknown expression in this scope.

  • By looking at examples, I can see that the authors somehow got their local variables to appear above the events that use them within the same scope, but I am not able to move them or otherwise coax them to do the same on my event sheet. It's like trying to unwrap a stick of butter with socks on your hands! (don't ask)

  • They are probably one level too low in scope then, screenshot of the area could help to solve this.

  • Ok, figured it out. Had to add a blank sub event, then move my globals onto it to make them local, then make my actions under that.

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