I am attempting to delete an object after a number variable on the object reaches zero. The number variable starts at a positive number and is decremented by 1 each time the screen is tapped/clicked. Once this number variable reaches zero it should be deleted. There are multiple objects within a scene that are part of a group. One object of the group is selected at random from this group to be the active object to have it’s internal number variable decremented.
What is the expected result
When the game is run, you should be able to tap or click the game window a number a times, each object will disappear (become deleted) and eventually no objects will be present on the screen.
What is the actual result
Sometimes one object will be deleted and no other objects are deleted regardless of how many times the screen is clicked or tapped. Sometimes all of them are deleted and sometimes only two of them are deleted.
Related screenshots
What the following event sheet is attempting to do is eliminate a single extension object that is picked at random from a group (consumable) of extension objects after a number of clicks or taps are made. A variable on the extension object is decremented each time “Take Bite” is called on the active extension object. Once this variable in the extension object reaches 0 the object is deleted. Once deleted, another object should be picked at random from the remaining extension objects within the consumable group. Sometimes this happens and sometimes it doesn’t. As in, it appears “Change the variable is_active of consumable: set to true” doesn’t seem to always trigger.
A - you click on screen and one object is picked randomly with each click and from that objects var 1 is subtracted
B - one object is picked randomly and tapping screen will subtract from this object and only this object until it is 0 and then he gets deleted and after that next random object is selected
C - you want to be able to click on any object and only that object that is clicked or touched will lose 1 in his var?
A - One object is picked upon scene start up. When you click, that picked object’s var is subtracted by 1. Then B exactly as you stated. This is the main interaction loop I am looking for.
C - I want to just click on the screen/within the scene and have the object that was randomly picked (via script/event sheet) to subtract 1 from its var. The objects themselves do not have any collision detection.
Thank you for taking the time to read this, I hope this clarifies the problem.
That middle event (with the count check condition) is applied to ALL consumable objects, whereas you want it to only apply to the one that’s just been bitten.
I suggest you drag that middle event to the right so it becomes a child of the first event - keep last event as a child of the middle event. The scope of the middle event will then be reduced to the one consumable that is active.
This however will prevent the random pick from working as it will only be applied to the bitten consumable. To fix that, add a “Pick all consumable objects” condition before the random condition.
Hey MrMen, thank you for reviewing my issue!
So I have a scene variable within the Consumables extension that keeps track of the amount of instanced consumables by adding 1 to the variable whenever a consumable is instantiated and subtracts 1 from this variable when an instance is deleted
I am doing this because I don’t know how to tell when an instance within the scene has been deleted so I simply check against this expression return value (which returns the value of this scene extension variable) and a separate scene variable I have in the scene which the objects are being instantiated in. So I believe I want to have this applied to all consumables.
I did try and re-arrange the events as you had suggested but the issue persists (I believe I implemented it as you had instructed):
I’ve refactored the code to better describe what I am trying to do. I am not sure why this doesn’t work. That is, why doesn’t another random consumable object become picked after the object is deleted?
Ah, one thing I forgot - in the event with the condition to pick all consumable objects, add an action to set the is_active variable to false. Otherwise you’ll end up with an increasing number of consumable objects with is_active set to true.