GROUP EVENT BUG?

  • hello everyone, i have a object called "frog", when the frog is in the trap the group "walk" disable, but if i have 2 frogs and only one in the trap the 2 frogs stop. I want to know if you can make these groups work in the 2 "frog" independently, that is, if the group stops only to stop for the "frog" that is in the trap for each.

  • I think you would be better off not using disable/enable groups to make things work. Its not really a good way to program in general compared to making your things work for objects based on correct conditions, the functionality in the group should work so it only happen to a frog if its trapped.

    A group is simply a virtual container so to speak for organizing and combining functionality in a more logic way or at least it should only be used as such.

    So instead what you should do is to check whether a frog is trapped or not, in the case it is, it shouldn't be able to walk.

    This can be done simply by using a boolean variable like "Is Frog trapped" = "True or False" and check for it as one of the conditions in the walk functionality. If you disable a group all functionality in that group will be lost for all objects, besides that you might end up with a lot of new problems if you suddenly enable the group and it then starts to affect all the frogs it shouldn't.

    In cases like these, where you make an event that should only trigger one object under a certain circumstance and it triggers two or more and you are unsure why, there are pretty much only two possible causes for that.

    1. Your picking is wrong, meaning you haven't made the correct conditions for the event.

    2. One or more variables for an object is not correctly set. In your program it could be that for instance, a frog "is Frog trapped" variable is not set to "True" when it collide with a trap.

    I would suggest you read this:

    How events works - https://www.scirra.com/manual/75/how-events-work

    Functions - https://www.scirra.com/manual/149/function

  • nimos100

    sorry nimos, but it is impossible, groups exist precisely because there are conditions that without groups it is not possible to do something, so I need something capable of making a group work on 2 objects independently

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • nimos100

    sorry nimos, but it is impossible, groups exist precisely because there are conditions that without groups it is not possible to do something, so I need something capable of making a group work on 2 objects independently

    Im sorry but that is simply not correct. Groups only functionality is that they can be enabled or disabled during runtime. But there are no difference in doing this compared to making events that wont run if certain conditions are not met. If you read the manual about groups the only example highlighted where disable and enable groups could be useful is for pausing a game, which I could see it being useful for, even though I would personally still prefer to pause the game some other way.

    Your example with the frogs based on your description is not a situation that can only be solved by disabling and enabling groups and honestly I don't think you can actually solve it doing it like that. But obviously if that's what you want to try, to make it work, you should go for it obviously. I only give you this feedback, because I think you are going off track, trying to solve your problem like this as it is really not a good practice. Seeing groups as a way to solve problems is just not a good way to approach programming I think. The issue you are facing is very common, just as if an Enemy is within range of a player then it should be able to shoot, but one there isn't shouldn't. And again you wouldn't or shouldn't solve such issue by starting to enable or disabling groups. The reason your program doesn't work is one of the two things if not both that I highlighted in the first reply. You get that fixed and your program will work for all frogs, whether they are trapped or not.

  • nimos100

    Whilst in rafaelsorgato 's particular case you're right that groups are the cause of the problem (if the group is disabled then necessarily you can't trigger any events within that group), it's misleading to say that you shouldn't be using groups in any circumstance. There are many valid reasons for doing so, most importantly because no checks are made against events in deactivated groups, which can lead to significant performance boosts, especially if those checks are on large numbers of objects/instances. Also deactivating and reactivating groups is a convenient way to reset top level "trigger once" conditions.

  • nimos100

    Whilst in rafaelsorgato 's particular case you're right that groups are the cause of the problem (if the group is disabled then necessarily you can't trigger any events within that group), it's misleading to say that you shouldn't be using groups in any circumstance. There are many valid reasons for doing so, most importantly because no checks are made against events in deactivated groups, which can lead to significant performance boosts, especially if those checks are on large numbers of objects/instances. Also deactivating and reactivating groups is a convenient way to reset top level "trigger once" conditions.

    I honestly don't think its misleading and think there is reason to be careful here and not confuse people new to C2. Obviously you can use groups and you can disable and enable them as you please and used correctly this will cause no problems. But disable and enable groups should never be used as problem solving, that is basically my main point.

    In regards to performance boost, im really not convinced that it is worth starting to do this, as I don't think the performance boost would be worth it, if at all possible to measure. The only valid argument I can think of, why you would disable groups to get a performance boost, is an argument to solve poor organization of conditions in events.

    An example of this can be illustrated with overlapping:

    Assume we have 1 enemy and 1 other object.

    1. Poor condition organization
    
    Enemy is overlapping <Something>
    Enemy is Alive = true
    ---------------------------------------------------
    
    2. Good condition organization
    
    Enemy is Alive = true
    Enemy is overlapping <Something>
    [/code:2qd868of]
    
    Assuming we are in a state of the game where we don't need to check for collisions, then looking at example 1, it could be argued that disabling this group would improve performance, because it would generate 60 collision checks and having a lot of objects would obviously create a lot of collision checks for no reason. However since C2 read conditions from top to bottom, simply making sure that your conditions are optimized correctly would solve the problem and a check vs true / false is done very very fast and would cause C2 to stop doing any collision checks after checking the first condition. So simply switching the conditions around would optimize the code.
    
    Obviously if your only condition is an overlapping check, sure disabling the group could improve performance if the number of objects are huge.
    
    But i think starting to see groups as a completely valid solution to solve a large amount of issues is simply not a good way to start thinking about programming in C2, because the moment you run into problems like performance, instead of thinking about how to optimize your code, you start relying on a "lazy" approach or what to say. And then you have these posts where people complain about poor performance in C2, but they might have done nothing to optimize their work. And I bet a lot of people are not aware or even concerned about that organizing their conditions correctly will also affect performance.
    
    So getting new users used to seeing the use of disabling groups as a good way to optimize code, just seems wrong to me as its not a good way to think about programming, compared to actually knowing the effect of what you are doing and how you choose to organize you code will affect performance and how you in general approach problems when they occur.
    
    Im not sure what you mean with resetting top level for trigger once conditions and how disable and enable groups is good here, compared to for instance making correct conditions? I won't argue to much against this, because im not sure what you mean.
  • Obviously if your only condition is an overlapping check, sure disabling the group could improve performance if the number of objects are huge.

    That was kind of my point - there are situations where it is useful to be able to simply turn off chunks of code, which would be a better optimisation than the ordering of conditions, where the checks would still be made even if the actions aren't triggered.

    But i think starting to see groups as a completely valid solution to solve a large amount of issues is simply not a good way to start thinking about programming in C2, because the moment you run into problems like performance, instead of thinking about how to optimize your code, you start relying on a "lazy" approach or what to say.

    I wouldn't consider it a lazy approach, rather learning the options that C2 affords you and then using them appropriately. Certainly you need to know what you're doing and I wouldn't advise beginners to dive in without an understanding of them, but that goes for pretty much all the features of C2. I'm certainly not advocating for using them as a catch-all for optimisation.

    Im not sure what you mean with resetting top level for trigger once conditions and how disable and enable groups is good here, compared to for instance making correct conditions? I won't argue to much against this, because im not sure what you mean.

    As I understand it, if you have something like:

    GroupA
    Trigger once | do action
    Condition X | do another action
    [/code:sqmlm5sj]
    
    Each time the group is reactivated the "Trigger once" action would fire.  This saves you having to set up a bunch of variables or other conditions to reset the Trigger.
  • >

    > Im not sure what you mean with resetting top level for trigger once conditions and how disable and enable groups is good here, compared to for instance making correct conditions? I won't argue to much against this, because im not sure what you mean.

    >

    As I understand it, if you have something like:

    GroupA
    >>Trigger once | do action
    >>Condition X | do another action
    [/code:pyujkxvs]
    
    Each time the group is reactivated the "Trigger once" action would fire.  This saves you having to set up a bunch of variables or other conditions to reset the Trigger.
    

    Im still not sure what the example is illustrating, meaning if I understand your code correct. You have one group, and in it you have two events. A "Trigger once" which do some action and then another event that tests for "Condition X" and if thats the case it does another action. But are these connected to each other? Meaning is Condition X suppose to be a sub event of "Trigger once"?

    But regardless I fail to see what exactly the enabling or disabling of the group is suppose to bring to the table here. I very rarely use trigger once my self except when doing something with sounds. So why you would make use of trigger once like in the example you made seems strange, not saying that there ain't a use for it, but I genuinely don't understand when you would make something like in the example.

    To me it seems like a sort of weird custom made function controlled by disabling and enabling a group. Could you give an example of a practical use for such an event, because I get the impression from what you wrote "As I understand it, if you have something like:" that you are not really yourself convinced what this is suppose to be used for, but do you recall the example or where you got it from, would be interested in seeing an actually example of this?

  • The "condition X" was to illustrate that usually you wouldn't have a trigger once in a group by itself, it relates to the other code in the group.

    One example of how I use this is having a number of game states that may be on or off at any time during play, each containing an independent loop. I put the code for each state in a group. When I want to turn off a particular game state I disable its group, switching off that loop. When I switch on the game state again the "trigger once" refires allowing me to reset any variables etc pertaining to that state.

    No doubt there are other ways to code this; I find this method to be straightforward to implement, easy to read and with some benefits towards optimisation as you can be sure that none of the code in that group is going to be checked or triggered whilst it's disabled. But hey, to each his own!

  • Ashley

    some ideia?

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