PDA

View Full Version : String into slot question



senseihitokiri
05-16-2006, 11:46 PM
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
05-17-2006, 12:05 AM
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
slot_string = "acc1";and then you use that for your slot. Why note just
$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
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
05-17-2006, 12:09 AM
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.

senseihitokiri
05-17-2006, 12:09 AM
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
05-17-2006, 01:10 AM
Perhaps the best way to handle that is with an external funciton like this:


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.

senseihitokiri
05-17-2006, 04:59 AM
seems like that will work, I look forward to testing it out in the morning... Thanks!

Presto Ragu
05-17-2006, 08:10 PM
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.