Page 1 of 1

Push.. and PopMapPosition() doesn't work with FindMapElement

Posted: Sat Apr 10, 2021 9:07 am
by Kurzer
PopMapPosition() doesn't restore the previous MapElement after using FindMapElement().

Code example:

Code: Select all


Define.s sCurrentID, sCurrentValue, sAnotherValue

NewMap Numbers.s()
  Numbers("1") = "I am 1"
  Numbers("2") = "I am 2"
  Numbers("3") = "I am 3"
  Numbers("4") = "I am 4"
  Numbers("5") = "I am 5"
  sCurrentID = "3"
  If FindMapElement(Numbers(), sCurrentID)
  	sCurrentValue = Numbers()
  	Debug "Current value: " + sCurrentValue
  	FindMapElement(Numbers(), "5")
  	sAnotherValue = Numbers()
  	Debug "Another value: " + sAnotherValue
  	sCurrentValue = Numbers()
  	Debug "Back to current value: " + sCurrentValue
  	Debug "Should be 'I am 3', but is still 'I am 5'"

Code: Select all

Current value: I am 3
Another value: I am 5
Back to current value: I am 5
Should be 'I am 3', but is still 'I am 5'
It doesn't explicitly say in the help that you can use this together with FindMapElement(), but I don't understand why it matters how the pointer to the current MapElement was changed.

I thought until now that the value of the map pointer is simply pushed onto the stack and later taken down again to restore the current map pointer with it.