H
Husbjörn
Guest
I wonder if someone would be able to elaborate on exactly how the "select greatest / least from list" instructions (opcodes 0x84 and 0x85) work?
Let's take an example of trying to select an opponent with the lowest HP to illustrate my point:
02 20b0 # Push current actor's active enemy mask
03 4160 # Push offset to HP value of (target) actor(s) as given in the above mask
80 # Pop last two values from the stack and push a list of all HP values for the current actor's active enemies
85 # Select the lowest value(s?) from the list at the top of the stack
I would have assumed that the above would push a 16-bit mask onto the stack with the bit corresponding to the enemy actor with the lowest HP set.
This does not seem to be the case however as more than one bit seems to be set. I could kind of understand if this happened if two actors had the same health which also happened to be the lowest but that is not the case. I then thought that it might push the actual index corresponding to the bit to be set instead (such that it for example pushes 3 for actor 3, rather than a 0%0010 mask) but that doesn't seem to be it either. The last possibility I can imagine is that it pushes the actual lowest HP value, but if this was the case what good is the instruction? While it would be possible to get the actual lowest HP value if we knew the actor to whom it belonged, the same cannot be done in reverse.
Or am I missing the point of these instructions entirely?
Another kind of associated question while we're at it, are lists on the stack formed in some way that they can be manually constructed (or read) by pushing / popping values / addresses or are they their own thing beyond manual control from a script perspective? I am guessing the latter since they tend to be described merely as "datatype 2X".
Let's take an example of trying to select an opponent with the lowest HP to illustrate my point:
02 20b0 # Push current actor's active enemy mask
03 4160 # Push offset to HP value of (target) actor(s) as given in the above mask
80 # Pop last two values from the stack and push a list of all HP values for the current actor's active enemies
85 # Select the lowest value(s?) from the list at the top of the stack
I would have assumed that the above would push a 16-bit mask onto the stack with the bit corresponding to the enemy actor with the lowest HP set.
This does not seem to be the case however as more than one bit seems to be set. I could kind of understand if this happened if two actors had the same health which also happened to be the lowest but that is not the case. I then thought that it might push the actual index corresponding to the bit to be set instead (such that it for example pushes 3 for actor 3, rather than a 0%0010 mask) but that doesn't seem to be it either. The last possibility I can imagine is that it pushes the actual lowest HP value, but if this was the case what good is the instruction? While it would be possible to get the actual lowest HP value if we knew the actor to whom it belonged, the same cannot be done in reverse.
Or am I missing the point of these instructions entirely?
Another kind of associated question while we're at it, are lists on the stack formed in some way that they can be manually constructed (or read) by pushing / popping values / addresses or are they their own thing beyond manual control from a script perspective? I am guessing the latter since they tend to be described merely as "datatype 2X".
Last edited: