enemy Alert is not working?

Please check it. I created events for enemy alert so if follows the character. But when the player is on the right side of the enemy it the enemy just flips back or it just keeps on flipping moving back and forth.

You really need to use “for each” event when you check distance and set the alert value and check the alert value. It is a special event that you can find on the top if you click the “Add” option.

I remember I have already explained to you maybe even with the same problem, why the for each event is necessary in such case. If you don’t understand I don’t think I can explain it any better, maybe someone else can but trust me, even if you don’t understand you do need the “For each object Theif” when you check the death value and distance and set the alert value and check the alert value otherwise it may causing errors in some cases because on of the instances met the condition, the other didn’t and GD get confused which instance has which value and which action to trigger on which instances. “For each” event helps to avoid that and handle each and every instance and their values such as alert and death individually for each

I haven’t realized until recently this is the project you are talking about when you mentioned it is become corrupted and you need to start from scratch. If I remember you have uploaded your project to the forum maybe you are lucky and the project file is still there.
Go to your control panel
Go to manage attachment and all your files ever uploaded to the forum is listed there and you can download it.
It is probably not the complete project, but at least you don’t need to start from scratch but if I can remember I was suggesting to start from scratch anyway because I experienced all kind of weird bugs when I tested caused by the logic you used.

I do Understand for each event but that was a different issue. I for got to state that I am for now just testing basic logic for a single object. No I don’t need the previous version, Thank God that it got corrupted. I did a lot of wrong things in the previous version. Thankyou any way!

This will not resolve the issue, but I’d like to ask you about this part:

From what I understand, it means this (in kind of pseudo code, not gdevelop):

If HP of Thief > 15 then HP of Thief = 15 If HP of Thief > 0 then HP of Thief = 0

What is the problem with this? Well, let’s imagine some case values and which conditions are activated:

Imagine that… Health of Theif is 25 at some point in time.

Is 25 > 15? Yes. Condition 1 will be executed.
Is 25 > 0? Yes. Condition 2 will also be executed.

That means that both actions on the right side should also execute, meaning that Health of Thief will be 0 (2nd condition action is do =0 to vaiable Health of Theif).

Now imagine that Health of Theif is 5 at some other point in time.

Is 5 > 15? No. Condition 1 will not be executed.
Is 5 > 0? Yes. Condition 2 will be executed.

Because 2nd condition is executed, again, the action “Do =0 to variable Health of Theif” will execute.

Conclusion: No matter what value is (2,5,6,10,50,250,etc.) 2nd condition (#15) will always execute, and you will always write =0 to variable Health of Theif.

That means that the first part #14 (Do =15 to variable Health of Theif) is not necessary, as it will always be overwritten by condition #15.

Perhaps you wanted to achieve something else, in which case, the conditions need to be edited.

Thanks for pointing that out. I wanted to write “Health of thief is >0 do health = 0”. So that is my mistake. But still the same problem occurs. There is something else to it. If I change the Pivot\Origin point to center from top left corner. the problem stops. but I don’t wanna do it.

I wanted to point out that these were the events in the first version of this project. That got corrupted. And it worked without using for each object event.

ddabrahim If I am using subevents should I be using for each event in the subevent too or just use it once in the main event and it will work.

I’m not 100% sure what is the problem if you have only a single Theif in your scene.
Are you sure you don’t change the value of LeftRight anywhere else in your project?

Last time the problem was with your project (and the reason I was suggesting to start over) you did change values all over the place and made it difficult to follow and debug what is happening and caused many bugs even ones that made something work that shouldn’t work and you were just lucky to got it work thanks to a mistake :stuck_out_tongue:

In short term, the For each is required mostly if you have multiple instances of the same object in your scene with custom values and conditions and you expect them to do different things based on their custom values and conditions at the same time.
In many cases it might just work without using For each, but it is not reliable, errors can happen any time depends on the conditions and values you are working with, to avoid such errors always best to use For each in such cases.

It depends on what you trying to do really. When GD get to a For each it basically go through every single instances and trigger all the events on the instances including the sub-events. If it what you want then you don’t need for each in the sub-events but only the main event need to be a For each and it should trigger all the events on every instances. But, in some cases you may want to do a “nested loop” when you want to go through multiple instances of object “A” and you want to check the state of all instances of object “B” for each object “A”. In this case you going to need a For each also in the sub-event:

Event: For each object A Sub-Event: For each object B

When I change the pivot Point of thief to centre it acts as I want. I don’t understand why