|
McGravin Beginner
Joined: 30 May 2002 Posts: 25 Location: USA
|
Posted: Mon May 24, 2004 9:59 pm
Question about variables and math operations. |
I have a question about variables. If I have a list of numbers seperated by commas and I save it as a string variable, is there any way to break that variable apart into individual numerical variables? For instance, if I have the variable @numbers saved as "2, 4, 7, 5, 11, 2, 6", how can I make each of those numbers its own variable?
Or, a more direct example of what I'm trying to do:
I have two sets of three-dimensional coordinates, each in its own variable. These variables are in a format much like "(-30784375, 314030, 19872)". I would like to take these two variables and apply Pythagonrean's theorem to them to calculate the distance between the two points. So that's sq.rt.((x1 - x2)^2 + (y1 - y2)^2 (z1 - z2)^2). Is there any good way to do this within zMUD? |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Mon May 24, 2004 10:11 pm |
Blah Math *shudder*
this might be something what your looking for to get started seperating the numbers using the %word() function
#SAY #numbers
outputs 2, 4, 7........
#say %word(@numbers,1,", ")
outputs 2
#say %word(@numbers,2,", ")
outputs 4 |
|
|
|
McGravin Beginner
Joined: 30 May 2002 Posts: 25 Location: USA
|
Posted: Tue May 25, 2004 12:48 am |
Actually, that works perfectly. Thanks! I had to play with some functions in order to get my equation to work out, but I got it eventually and it works fine, now.
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Tue May 25, 2004 4:50 pm |
This would be simpler if you used a list variable and even simpler than that with a record variable.
Comma-separated values (what you have)
#VAR CSV {-30784375, 314030, 19872}
#SAY The first number is %word( @CSV, 1, ", "), the second is %word( @CSV, 2, ", "), and the third is %word( @CSV, 3, ", ")
List variable
#VAR List {-30784375|314030|19872}
#SAY The first number is %item( @List, 1), the second is %item( @List, 2), and the third is %item( @List, 3)
Record variable
#VAR Record.x {-30784375};#VAR Record.y {314030};#VAR Record.z {19872}
#SAY The first number is @Record.x, the second is @Record.y, and the third is @Record.z
I think you can see that the third method is by far the simplest for use in calculations.
NOTE: Also see #ADDITEM and #ADDKEY |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|