Toribash
hi Sir, sorry for late reply... I was a bit busy in some other assignments...
I got your point.. but if I want to do this task based on the strings then how can I do that?
This is the example:
<?xml version="1.0" ?>
- <catalog>
- <equipment id="eq101">
<name>ruler</name>
<material>plastic Guide</material>
<measures>length</measures>
<unit>meter</meter>
<size>12</size>
</equipmentid>
<equipment id="eq102">
<name>ruler1</name>
<material>metal Guide</material>
<measures>length</measures>
<unit>centimeter</meter>
<size>2</size>
</equipmentid>
</catalog>

now in the above xml file, there are two sets of info, I can say... they are equipment id 101, 102...
now I will take all the info into one string say text.. so now in text I have full file ....
now I need to take the first string that is the content in between, <equipmentid> to </equipmentid> I will save the string as a first content of some table may be.... and so on... Can you please help me for the task which is explained above...

Thanks in advance!!
sorry again...
assuming that the content of the .xml file is stored in a variable called "text":
for a, content, b in string.gfind(text, "(<equipment.->)(.-)(</equipment>)") do
    -- content contains everything between <equipment ...> and </equipment>
end
I guess in the text you posted it's supposed to be "</equipment>" not "</equipmentid>".
Signature temporarily out of order.
Thanks alot!!
yes, in the previous posts I metioned.. equipment and not equipmentid... but they are same only...
Sir I got solution from your side only partially... can you please tell me how it will work ?
it seems to be a bit complex..what is a and b in that for loop?

Thanks again
gfind(text, regex) returns a function which each time it is called returns the next occurrence of regex in text. So for example:
 findIt = gfind("I am a sentence", "a")
 findIt() -- returns "a" (the one of "am")
 findIt() -- returns "a" (the single "a")
 findIt() -- returns nil (no more a)
This works with regular expressions as well:
-- %w+ means any string of alphanumerical characters that is not empty
findIt = gfind("I am a sentence", "%w+")
findIt() -- returns "I"
findIt() -- returns "am"
findIt() -- returns "a"
findIt() -- returns "sentence"
findIt() -- returns nil
The next thing you can do is put stuff in parenthesis, in which case gfind will return only the stuff in parenthesis:
 -- search for two word, return seperately
 findIt = gfind("I am a sentence", "(%w+) (%w+)")
 findIt() -- returns "I" and returns "am"
 findIt() -- returns "a" and returns "sentence"
 findIt() -- returns nil
Now here's a little update on the loop (there's no need for a and b):
for content in string.gfind(text, "<equipment.->%s*(.-)%s*</equipment.->") do
    -- content contains everything between <equipment ...> and </equipment> without leading and trailing whitespace characters.
end
what this does is go through text until there is no more occurrence of <equipment ...>any text</equipment> and store the stuff between the tags into content.
Signature temporarily out of order.
Excellent!!

Thanks a lot for your wonderful explaination!!
Surely it is very much helpful.....
I will again get back to you if I will have any doubt about LUA...

Thanks again!
You can get the rotation with
local rot = get_body_info(player, bodypart).rot
It returns a table with elements r0 - r15. Those represent a 4x4 rotation matrix like this:
 / r0   r1   r2   r3  \
|  r4   r5   r6   r7   |
|  r8   r9   r10  r11  |
 \ r12  r13  r14  r15 /
There's also a the function
set_body_rotation(player, index, x, y, z)
but it doesn't appear to do anything and isn't listed in the scripts/sdk folder, so I guess it's deprecated.

I don't know of any other function for setting rotation. Neither for bodyparts nor joints.
Last edited by psycore; Jul 18, 2012 at 06:04 PM.
Signature temporarily out of order.
Hello, if I have the number "1002", I need the script to be able to say, (Load 1.png, 0.png, 0.png, and 2.png). But that's not all I want it to be able to do. So essentially my question is more to do with basic Lua. How can I get any arbitrary number value and then have the script be able to detect what value is in the ten thousands, the thousands, the hundreds, the tens, and the ones place?

Also, how to to the same with letters?

thanks
local number = 1002
local strnum = tostring(number)
for i = 1, #strnum do
    echo(tonumber(strnum:sub(i,i))) -- echos 1 then 0 then 0 then 2
end

-- for strings:
local str = "asdf"
for i=1, #str do
    echo(str:sub(i,i))
end
For that "Load 1.png 0.png ..." you could also do:
local num = 1002
local str = "Load "..string.gsub(tostring(num), "(%d)", "%1.png, ")
-- strip last comma and space
str = str:sub(1, #str-2)
echo(str)
Signature temporarily out of order.
You can also use maths to get a particular digit:

lua code:
function getDigit(num, position)
return math.floor((num / (10 ^ (position-1))) % 10)
end

echo("Third digit: " .. getDigit(423, 3))
-- Third Digit: 4
:D