Wrapping for last weapon

Here is the code:

func next_weapon() -> void:
	var index = get_current_index()
	index = wrapi(index + 1, 0, get_child_count())
	equip(get_child(index))

func previous_weapon() -> void:
	var index = get_current_index()
	index = wrapi(index - 1, 0, get_child_count())
	equip(get_child(index))

However, scrolling down does not wrap around to change weapons. It does change once, but does not continue changing as the scroll wheel scrolls down. I’m thinking this is because get_child_count() returns a value of 2 and so when the index returns 0 and subtracts 1, it returns 2 which is not assigned to any value in the array (although… shouldn’t it still continue subtracting on each scroll? idk). Are others experiencing this?

Hi Sighless,

This is a bit of an odd issue as my code is the same as yours as far as i can see and mine works as intended.
Can you post the entire WeaponHandler script as although i am sure it is fine we can rule out the scripting in this script being an issue.

Thanks in advance

and just a quick one on that as well. if you could also pop a quick screenshot of your player scene tree as well please.

Cheers

1 Like

Ah, I figured it out! Another silly mistake. I had tried to implement scrolling from the previous lecture as a challenge to myself and accidently left scroll down for “weapon_2” in the input map. Removed that input and it now works as expected

1 Like

nice one on squishing that bug and getting back on track :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms