XP, Levels , while loop

I made some small progress with “Portal Ranger”, in area of UI and enemy, but when it comes to levels and stats I wonder how to go about it.

I expect to make maybe 20 instances overall, so wonder how should I put down ratio for how many kills are needed to progress level, and how this number increase in overall experience.

Another challenge is check for level itself which I guess have to be “while loop” checking for xp.value to increase level when above.

Some tips for this? I mean it not necessarily important but it be nice to have option go easier by farm on mobs or harder by trying more difficult enemies without matching level.

This also makes me asking : when player level up should mobs on next spawn match players level?

level scaling breaks progression, so making mobs match player’s level on next spawn might be annoying, instead you could add better types of mobs that have higher levels or smth like that

2 Likes

Just connect some function that counts xp to signals emitted when enemies die, quests are completed etc. Have the signals contain the amount of xp you want. Or instead of using signals, make the script a global.

A while loop would continue forever so i would try to avoid that.

1 Like

current solution is from course

var level := 1
var xp := 0:
	set(value):
		xp = value
		var boundary = percentage_level_up_boundary()
		
		while xp >= boundary:
			xp -= boundary
			level_up()
			boundary = percentage_level_up_boundary()
		update_stats.emit()

func level_up() -> void:
	level += 1
	strength.increase()
	agility.increase()
	speed.increase()
	endurance.increase()
	level_up_notification.emit()
	
func percentage_level_up_boundary() -> int:
	return int(50 * pow(1.2, level))

so while should only runs when value is set right?

Yes, and it looks more like its a while loop for situations where you gain multiple levels at once.

I thought you meant having a while loop for the entire level up logic when i said it would cause problems.

1 Like