I am working on a project that is based on a sliding puzzle. I am creating the objects in the beginning of the scene. I have to create the object first before I can use it in the repeat event else the objects will not be appearing on the screen and I do not know the amount of frames the sprite is. This all is variable as I want to be able to simply upload the images in the sprite and it will automatically calculate the amount of tiles the puzzle is made of.
In the beginning I give the object variable Nr the nr 99. In the actions later I want to delete that object as it would interfere with the routine that determines whether the puzzle is solvable after randomizing the tiles. But it does not. When I pick all slides objects it says there are 10 instead of 9. I have tried all kinds of different approaches and am stuck with what to do. Anyone here could tell me what I am doing wrong?
The sprite has 10 Frames.
At the beginning of the scene I create the objects then I delete the object that has the variable Nr set on 99.
The inversion calculation that would determine if the puzzle is solvable is inccorrect as it picks up 10 objects instead of 9. The delete is not done.
The result is 10
Try assigning the variable’s value on a separate event or even a subevent of the one that creates the object. Object variables behave oddly sometimes with new objects. Maybe it’s a timing issue and they’re not created until the end of the event.
You tried a pick all slides, id is 99, delete slide?
Also what Keith says has happened to me before when assigning object variables after creation so that’s worth a shot.
Both things and combinations of them give the same result unfortunatly.
Well what’s the debugger say.
It’s weird. If you create an object, change its value and then create more objects and set their values it changes the 1st object as well. I guess because it’s a subevent, it’s still picked.
This creates 2 objects with the same ID and the debug output is 1 and then 2.
This creates 2 objects with the correct IDs and the output is 1 and 1
This is because events that deal with objects have “Object Lists”, and all subevent conditions (and creation actions) just add to the current object list, so it will apply to all of them.
Indeed in the debugger it shows that the variable of the first object is changed to the number 8 (which is the last object created its number too). In a sense I could technically work with that because I ignore that tile anyways as it is the last one and the one that is representing an open space. Anyways. I tried your example Keith and it did not change anything on my end. Now I have a working model as seen in this example when I put it under a mouse button released condition.
However if I do exactly the same thing under an at beginning of the scene condition it does not work. Also It does not set the objects animation frames correctly. I have to put in a seperate event with condition that does that according to the objects variable Nr. (see above screenshot)
I do not understand the “Object Lists” problem!. How is it that the other 8 objects are not affected by it but only the first. If they are in the same list? It makes no sense from a development point of view. I create an object and give its variable a value. Wherever elsewhere I create an object I expect the next condition to only affect that object. It does so within the repeat event. Yet it is the object that is totally outside that event that is affected.
It took me a bit. The object list starts new for each main event but it retains its information for subevents. The difference with the repeat is the looped events are all on the same level. After each repeat event it goes back to the previous list.
you add an object (main level, you have 1 object)
---- you add an object (subevent, you now have 2 objects)
---- you add an object (not subevent, you still have 2 objects, the 1st and the last)
--------- you add an object (subevent, you now have 3 objects, the 1st, 3rd and 4th)
If you add this to a new project, with a sprite and press space
The debugger/console would be
It sometimes seems complicated but there is a method to the madness. There’s a hierarchy. Everything happens on its own level, events and subevents and subevents of those.
To follow-up. In your last image. The repeat is still a subevent of the event that creates the object you want to delete.
If you add a subevent of the [cursor] main event in between it and the repeat and then move the add object and variable action to it. It should work. Here’s a photoshopped version.
I solved it through this code. Even though. Still the original created object its variable is also changed by the repeat event. No matter whether I put it as a subevent or not. Yet this is the most elegant solution I could come up with. It creates exactly a 3x3, 4x4, 5x5 etc puzzle depended on the animation of the object slides and removes the unwanted two slides at the end. The result is now 9 instead of 10 slides and the inversion calculation can be made to see if the puzzle is solvable after randomization of the slides (which is my next challenge :-). Thank you all for your help it is greatly appreciated.
I’m glad you found a fix. Instances still confuse me at times. I feel silly, I was focusing on the wrong thing. I’ve done stuff like this before but we don’t always see the answer.
You could use different variables. Use one variable for the first object and a different for the second. That way even if the first gets changed, you don’t use the 2nd variable, you use the 1st.
Indeed that is how I have solved it now.