Reg number from variable?

Users who are viewing this thread

Status
Not open for further replies.

MountainBlade

Sergeant Knight at Arms
I want to replace this:
    (assign, reg0, 0),
    (assign, reg1, 1),
    (assign, reg2, 2),
with code that does the same thing but up to any number, based on a variable:
    (try_for_range,":rnum",0,":num_combatants"),
      (assign, reg":rnum", ":rnum"),
    (try_end),
Obviously this doesn't build because of reg":rnum". Is there a way to base the reg number you write to on the contents of a variable? Or will I just have to make a try block for every reg?
 
That would be great if it were possible, but I'm pretty sure it's not.

Do you really need all the regs assigned separately?

Because the obvious workaround would be to use the same reg in a try_for_range and then also execute the operation in that try block. So say if you want the trp_id in reg0 and want that in a message:

try_for_range, ":troop_no," 0, 30,
assign, reg0, ":troop_no",
display_message, "@troop nr is {reg0}",
try_end

Cause the problem with the other method is also that you'd have to know on the other end of the script how many regs were actually set. Of course you could put that number into reg0, so assign values into reg1 up to regx and then store the nr for x into reg0 so you know how many regs you have to work with afterwards.

But again, I've never seen this used and I don't think python (or mnb python anyway) allows it.
 
MartinF said:
That would be great if it were possible, but I'm pretty sure it's not.
Too bad. It's no big deal in this case, it doesn't go that high anyway, but it would've been handy.
Do you really need all the regs assigned separately?
For shuffle_range. That only works on a range of registers afaik
Cause the problem with the other method is also that you'd have to know on the other end of the script how many regs were actually set. Of course you could put that number into reg0, so assign values into reg1 up to regx and then store the nr for x into reg0 so you know how many regs you have to work with afterwards.
You can just use whatever variable you used to decide the max number (:num_combatants here) and make it global if you need it in another script.
 
Put your values in an array (e.g. slots on a dummy troop), and then set 1-10 in reg1...reg10. Shuffle the regs, then use them as (now random) indices to your array.
 
fisheye said:
Put your values in an array (e.g. slots on a dummy troop), and then set 1-10 in reg1...reg10. Shuffle the regs, then use them as (now random) indices to your array.
Sorry, but I don't understand. What would that do? Why would you even set up an array for that if the regs already have the values?

I did it like this:
    (assign, reg0, 0),
    (assign, reg1, 1),
    (try_begin),
      (ge, "$num_combatants", 3),
      (assign, reg2, 2),
    (try_end),
    (try_begin),
      (ge, "$num_combatants", 4),
      (assign, reg3, 3),
    (try_end),
    ....
    (shuffle_range, 0, "$num_combatants"),
The first two have to be set in any case, that's why they have no try.
 
Sorry, I misunderstood your question, please ignore my post, it's not relevant to what you're trying to do.
Oops. :oops:
 
Status
Not open for further replies.
Back
Top Bottom