Variable Isolation
I've been trying to understand how does that crazy 'Dink's Trunk' script works and I've got this question:
How can I isolate a variable number?
As some know, that script saves in a single variable every Dink's items with a monster number Ex.: 126532485

So, the third number from left to right is the number of bombs (maybe not, just an example) as we can see it's 4.
How can I take that number 4 out from that others and use it?
&trunk = 126532485;
&bomb = ???;
You can use the fact that variables are integers. The largest value for an integer is 2,147,483,647 so you have 10 digits to work with. So you'll do something like this: (Note: I haven't looked this up, so this isn't guaranteed to work...)
<number you want> is the number you want counted from the right. So in this example this would be 3.
EDIT: This script does look a bit ugly... I wonder if there's an easier way...
&trunk = 126532485; int &temp1 = &trunk; int &temp2 = &trunk; int &loopvar1 = 1000000000; int &loopvar2 = 11; loop: &loopvar2 -= 1; &temp1 / &loopvar; if (&loopvar2 = <number you want> ) { &bomb = &temp1; } &temp2 -= &temp1; &temp1 = &temp2; &loopvar1 / 10; if (&loopvar2 > 0) goto loop;
<number you want> is the number you want counted from the right. So in this example this would be 3.
EDIT: This script does look a bit ugly... I wonder if there's an easier way...
Attach this script to a sprite and talk to it to test it.
Just as I finished this I saw that metatarasal beat me to it so I haven't really checked his script yet.
void talk (void) { int &n4 = 1; //&n3 is the number you want counted from right to left. //In this example we want the 4 in 126532485 which is the 3rd number. int &n3 = 3; if (&n3 > 1) { loop: &n4 *= 10 &n3 -= 1 if (&n3 > 1) { goto loop; } } //&n1 is the number you're taking a number from being 126532485 in this example int &n1 = 126532485; int &n2 = &n1; &n2 /= &n4; &n4 *= 10; &n1 /= &n4; &n1 *= 10; &n2 -= &n1; //Showing the outcome. say_stop("&n2", ¤t_sprite); }
Just as I finished this I saw that metatarasal beat me to it so I haven't really checked his script yet.
Interesting... I wrote a script that does the exact same thing, but as a helper function I can call from anywhere and pass through the variable and digit to extract, but it's much longer and has much more redundant code. Gonna take a look at your scripts and see if I can simplify it

There was also a script in someone's FIFO and Variables in DinkC tutorial under the Multiple values in one variable section. Really useful.