String into slot question

S

senseihitokiri

Guest
I might be hitting a mental block here but can someone help me out with this.
I'm trying to loop through accessory slots to assign items into them. I create a string that turns into acc1, acc2, and acc3, but I can't figure out how to get the slot variable from it. I've been trying stuff like

string slot_string;
slot_string = acc1;
slot A;
A = $slot[slot_string];

and that doesn't work, so I've been just randomly bashing code out that doesn't quite work... well work at all. Does anyone have a recommendation. I'm going to take a break from this "tiny" project that was originally only 30 lines and is now over 600 lol

Oh, edit... BTW I did have " around acc1.
 

macman104

Member
Two things:

1) You can edit your own posts, by clicking on "modify" in the top right corner of your posts.

2) for the line of code that's
Code:
slot_string = "acc1";
and then you use that for your slot. Why note just
Code:
$slot[acc1]
Would you mind posting your original code, because I'm still kind of unsure what exactly you are trying to accomplish here?

Also, you can initialize and assign a variable on the same line. So your four lines could be
Code:
string slot_string = "acc1";
slot A = $slot[slot_string]
Although, I'm not sure if it will work, because I don't know if the value inside of slot is technically handled as a string.
 

Tirian

Member
The parameter for $slot isn't a string. I don't know quite what it is, I guess there are two thousand built-in constants in the program. But you want to say $slot[acc1], not $slot["acc1"] or anything like that.

What is it that you're trying to do? I have a feeling that we can script around whatever it is.
 
I couldn't modify it because I wasn't registered at the time fo that post.

while( acc_num < 4 ){
   //Creat the slot
   string slot_num;
   slot_num = "acc" + int_to_string(acc_num);

   slot acc_slot;
   acc_slot = $slot[slot_num];

   acc_num = acc_num + 1;
}
 

Tirian

Member
Perhaps the best way to handle that is with an external funciton like this:

Code:
slot int_to_acc_slot(int n)
{
  if (n==1) return $slot[acc1];
  if (n==2) return $slot[acc2];
  if (n==3) return $slot[acc3];

  cli_execute("abort illegal accessory slot number");
  return $slot[familiar];
}

I have to confess that I haven't tried the abort command like that, but I think that's how it works.
 
Or...

You could use the int_to_slot() function.

int_to_slot( 5) is for acc1,
int_to_slot( 6) is for acc2,
int_to_slot( 7) is for acc3.
 
Top