How do I prevent variable checks on too many instances?

Get help using Construct 2

Post » Wed Jun 29, 2016 9:29 am

I have a lot of objects that have an Instance Variable called 'Status' .

The objects will change their behavior based off of 'Status'.

0 = Idle - Does nothing.
1 = Creation - Animate when being created.
2 = Destroy - Animate when being destroyed.

The objects don't move and don't have health, they are created and destroyed by variable changes.
The player Creates or Destroys using an in-game Item.
Each object is created into a group and each group is given a 'GroupID' Via Instance Variable.
If group 6 is destroyed every object with 'GroupID' 6 will be destroyed at the same time.
If group 5 is destroyed the next group created will be given 'GroupID' 5.
Only the highest 'GroupID' can only be destroyed at any given tick, but so can the next 'GroupID'.
Most of the time 'Status' will be 0. There is a chance a player can Create or Destroy quickly.

Is there a way to only enable a 'Function' if a 1 or 2 in the variable 'Status' is present in the layout?
I don't want it checking 800+ objects every single tick, but if they are destroyed or created they need to react instantly.

The only thing I could think of was creating a 'leader' in each group and then checking the variables needed on the 'leader' object. If the leader objects has the required variable then apply create/destroy to all of the same objects with the same 'GroupID'. Is that a proper solution or is there one better? I assume the 'leader' objects would have to be a 2nd object to prevent the the extra variable checks.

I only came up with it because of groups, is it possible to do it without groups?
B
62
S
35
G
13
Posts: 232
Reputation: 12,402

Post » Wed Jun 29, 2016 11:47 am

first of all my English is not good and may be I do not understand it properly and my answer will depend on what i understand
example capx
If this was not your question then please let me know.
Image
B
64
S
39
G
45
Posts: 651
Reputation: 32,214

Post » Wed Jun 29, 2016 1:28 pm

Have you thought about the conditions "on object created" and "on object destroyed" ?
Though "on destroyed" will not allow you to animate their destruction, because it is triggered after they are removed, but you could work around this by animating their destruction into a separate object type that is spawned "on destruction" and then destroyed when its animation ends.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Wed Jun 29, 2016 1:44 pm

@Unconnected
if the objects ONLY get created or destroyed as a direct response to the player's input, then you don't need to check their status every tick, or ever - unless the player takes action.
When the objects are created (and given an initial status of 1) you would start the creation animation. You would also need an event: On Animation "CreateObject" Finished to set the status to idle (and show the idle animation if necessary).
When the player destroys a group you can set the status to 2 and start the destroy animation. Then an On Animation "DestroyObject" finished can remove the object from the screen.

By using triggers like that, there is no need to constantly check what is happening to the status of an object.
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Wed Jun 29, 2016 7:20 pm

Sorry I didn't realize how poorly I explained what I was needing, so I will try again.

I meant every tick the trigger is running. So does Construction 2 group objects by what a variable equals? Or does a trigger still check every object as long as it's running, or just when it starts? I'm not sure how it would know which objects to trigger and how many times if it didn't check all objects at least once to get info. I try to only use triggers, just not 100% sure how they work yet.



Can a 'Function' run multiple times at the same time? If Group 6 and Group 5 both call it a few ticks apart?

If so then can someone show me how to have a loop in a function that loops as long as an objects animation frame is between 0 and the highest frame available (25). A loop based off of animation frame was my main issue, should I have created a 'CurrentFrame' Instance Variable? I currently have a 'SetFrame' Instance Variable that can be -1, or 1 so frame can be changed accordingly based of of 'Status' Variable.

I know how to make a loop repeat a specific amount of times, just not sure how to make a trigger loop that runs until a variable is equal to a specific value.

I have thought about on created/destroyed, that is basically what the Capx was (On click play animation "create" on click play animation "destroy").. The Capx was very similar to what I needed. I need more control of the objects frame in case it gets destroyed during creation animation.

I am aware of Setting 'AnimationSpeed' but once the object reached it's max frame it seemed to ignore any commands.
B
62
S
35
G
13
Posts: 232
Reputation: 12,402

Post » Wed Jun 29, 2016 9:22 pm

No solutions, since i have no darn idea what you are up to. Just ideas 4 you. How to use animation triggers, functions and an array.
In this one only the oldest created can be destroyed. Creation happens kinda random when clicked on an empty position. Newly created groups can be destroyed when it is their turn to be the oldest group.

https://www.dropbox.com/s/fhk848s835jq3 ... .capx?dl=0

It's not sorting many objects, nor rearranging them, it just sorts a GroupId. And picks according.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jun 30, 2016 1:48 am

I asked how triggers work, if it checks every object while it is running, if it checks all objects only once, or if it knows which objects are needed by some kind of list or something.

Can a 'Function' run more than once at the same time for different objects if it is called more than once within a few ticks apart?



I asked for an example of a while loop, because it seems to be what I need. I can't find an example because nobody uses them anymore it seems.

I need a loop that will run every 0.5 seconds while a variable is not equal to a specific number. I only know how to run a loop a specific amount of times, or once for every object. I can't seem to find a way around this.
B
62
S
35
G
13
Posts: 232
Reputation: 12,402

Post » Thu Jun 30, 2016 3:49 am

I found out you can use Repeat (Variable <> 1)

Right now I have:

'Repeat' loop with a condition of 'less than 25'.
The actions are 'wait X Seconds' and 'add to'
See below:

Event/Condition -------------------------------------------------------- Actions
Repeat (Variable is not equal to 1) Times---------------------- Wait 0.5 * loopindex Seconds.
'GroupFrame' is less than 25-----------------------------------------Add 1 to 'GroupFrame'


0.5*loopindex is supposed to slow down the loop so it adds 1 to 'GroupFrame' every 0.5 seconds.

What it is doing is ignoring the 'wait' function. When I run the function in debugger 'GroupFrame' jumps to 25 automatically.

Can someone show me how to make the loop slow down?

I am okay if you change the loop completely if it will be better. I am kind of just Frankenstein-ing it together right now anyway.
B
62
S
35
G
13
Posts: 232
Reputation: 12,402

Post » Thu Jun 30, 2016 4:55 am

what about doing it backward such as create a variable call it max creation and you could do something if max creation is not zero then every 5 sec spawn this and then -1 to the max creation.

so that you could effectively loop it without looping and it gives you the room to adjust how fast and how slow it can create something and you can do the same for destroy as well. You can also do something like when player trigger something add 10 to max creation and then that code will keep going until it hit 0 which is ten sprite.

And this can just be a control group. I hate using loops it tend to mess with me. so which is why i do that trick

Is that what you want ?
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Thu Jun 30, 2016 5:34 am

I figured I was probably going in the wrong direction so I created a Group Leader and every group leader gets checked every few seconds. Every group is made using a number sequence. 8, 24, 48, 80, 120, 168, 224, etc... I am able to actively check 12 objects instead of 624. If the group leader has a variable change the whole group changes accordingly.


I still find it hard to believe I was having trouble finding a 'While' or 'Repeat' loop example with an efficient 'Wait' built in. I finally found a solution on a forum and it wasn't working for me for some reason, it even looked exactly like what was posted.

I would have rather had a Trigger Loop with a timer, but I couldn't figure it out. This will do for now.

Starting to think of it, the problem in the loop was probably a variable type.
I know when I make a 'Zoom' Variable it has to be global or it won't work... Maybe it is the same issue.


@Gearworkdragon
Not fully but I did something similar and was posting about it when you typed your post. Thank you for your time.
Last edited by Unconnected on Thu Jun 30, 2016 6:47 am, edited 3 times in total.
B
62
S
35
G
13
Posts: 232
Reputation: 12,402

Next

Return to How do I....?

Who is online

Users browsing this forum: Magistross, mihirolover, tarek2 and 10 guests