Get Experience Points

Get help using Construct 2

Post » Wed Jan 20, 2016 2:53 pm

Hey there, i have a quiet simple question, it shouldnt be too hard, but im really struggling with it. I have build a leveling system, which itself works totally fine.
The enemy AI is based on a "state-variable", as example, 1 is idle, 2 is walking right etc. So if you kill an enemy, it's state is set to "dead" and you recieve experience points.
The enemies are all in a family called "enemies" and they are all handled as separate instances.
My problem now is, damage and states works fine for separate enemies, but when it comes to give experience points, my problem starts. My setup right now is like this. (I tried many many different setups)

For each - enemy
Health is >0
Trigger once
Set variable to "dead" and add points to variable "exp" for player

Now the exp points will be added continiously and i understand why, but i still couldnt figure out a legit way to just add exp points ONE time on enemies death.
B
11
S
3
G
2
Posts: 76
Reputation: 1,891

Post » Wed Jan 20, 2016 3:35 pm

So why not add only on enemies death?

So add the action giving experience points to the event that makes the enemies health go under 0..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Jan 20, 2016 3:48 pm

If i use on destroy it works fine, but i want to leave the dead enemies on the ground. So i have to put them to state "dead".

The event that makes it go down, is the players collision box colliding with the enemy. If i put the exp points to the attack action + hp below zero, it doesnt work.
B
11
S
3
G
2
Posts: 76
Reputation: 1,891

Post » Wed Jan 20, 2016 4:02 pm

For your solution you can add a boolean instanca variable which determine if exp already got calculated or not... BUT checking all enemies all the time just for calculating exp points seems to be like a connon for a fly.

Each enemy/target should have an instance variable "health", then

On BULLET collision with TARGET
- decrease TARGETs health points
- if TARGETs health points <= 0
-- run "dead" animation
-- calculate XP

Something like that should work, if it doesn't, just give us a screenshot cause there is something else giving you problem.
ImageImageImage
B
27
S
16
G
80
Posts: 1,016
Reputation: 44,751

Post » Wed Jan 20, 2016 6:33 pm

Ok here is my collision event.
Image

And here is the experience point event.
Image

The damage works fine. The strange thing is, also the experience points work fine, but only when i kill the first enemy, after the second one the exp will be added continiously.
The question is, how to make it just happen one time. Even "trigger once" didnt work, cause the enemy is set to state 11 "dead" and will continiously give exp. So how can i stop it?
B
11
S
3
G
2
Posts: 76
Reputation: 1,891

Post » Wed Jan 20, 2016 6:52 pm

Optimally, HEALTH <= 0 (and any condition filtering the For Each) should go above the For Each.

If you don't destroy the enemy right away, your only resort would be to use a boolean or another state variable (using AI_STATE <> 11 could be ok too if an AI_STATE doesn't change once dead). "Trigger once" in that context doesn't make much sense, in fact, using a "Trigger once" in a loop is one sure way to get unwanted behavior. As soon as it loops more than once, "Trigger once" get mixed up and make each iteration a "new trigger", thus explaining your problem.

Also, the "Trigger once" in the collision event is redundant, and you might as well remove it altogether.
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Wed Jan 20, 2016 7:29 pm

I think in this case I would just put the

enemys health < 0 subevent

as a subevent of the collision event..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jan 21, 2016 10:04 am

Thank you all guys for your help, but somehow it still doesnt work. I guess i will go with destroy enemy and try some kind of workaround.
B
11
S
3
G
2
Posts: 76
Reputation: 1,891


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests