GameMaker Not adding XP.

M

MrTholl

Guest
GS2 Problem 13.png GS2 Problem 14.png I am trying to add XP when I kill an enemy but it's stuck at 20.
 
M

MrTholl

Guest
Even if I set global.enemy1_exp to global.enemy1_exp+global.enemy1_exp it stays at 20.
 
T

TheRBZ

Guest
try setting it to 100 or anything other than 20 and see if it's still 'stuck'?
 

TsukaYuriko

☄️
Forum Staff
Moderator
To repeat, your code does this:

Set global.enemy1_exp to 10, overwriting its value.
Add 10 to global.enemy1_exp.

Can you see the problem now?
 

TsukaYuriko

☄️
Forum Staff
Moderator
You're already doing this. Keep doing that.
However, you're also setting it exactly to 10 right before that, clearly visible in the screenshot you posted. Don't keep doing that. Remove it from your code.
 
M

MrTholl

Guest
GS2 Problem 16.png GS2 Problem 15.png I moved setting the variable to 10 in the create event and redid the step event but now this.
 

FrostyCat

Redemption Seeker
In D&D, any box that reads "Relative" means "add to the existing value". You can't do that on a variable that doesn't already have a value. And given the expression (current experience plus something else), that looks like the total you want already, so the Relative box should be off in the first place.
 
M

MrTholl

Guest
It does have a value. The experession is global.enemy1_exp+global.enemy1_exp.GS2 Problem 17.png
 

FrostyCat

Redemption Seeker
Read the error message again. It is complaining about enemy1_expTotal having no existing value, not enemy_health or enemy1_exp.
 
M

MrTholl

Guest
GS2 Problem 17.png GS2 Problem 18.png When its not relative its stuck at 20 when its relative its stuck at 30.
 

FrostyCat

Redemption Seeker
You have neither traced through your nor followed TsukaYuriko's advice. Re-read her post. Stop trying to reinitialize enemy1_exp.

Get rid of all 3 global variable actions from your screenshot. Then replace it with a single Set Global Variable action with Name set to enemy1_exp, Value set to 10 and Relative checked. It doesn't get any simpler than this.

And in case you aren't sophisticated enough to see it, I'm telling you right now that both TsukaYuriko and I are at the end of our ropes with your continued inability to exercise common sense.
 

FrostyCat

Redemption Seeker
I told you to replace the 3 global variable actions in your Step event, not the initializations in your Create event.

This should be in your Create event:
  • Set global variable enemy_health to 100
  • Set global variable enemy1_exp to 0
This should be in your Step event before the Destroy Instance action:
  • Set global variable enemy1_exp to 10 (Relative box checked)
Think it over. Use some common sense. Read instructions properly and mean it.
 
Top