people playing: 310
servers online: 89
games played: 73,110,444

  Toribash Community » Toribash » Mods » Lua scripts
Reply
 
Thread Tools Display Modes
Old Jul 6, 2012   #471
pranavkulkarni
Junior Member
 
Join Date: Jul 2012



ok.... I was planning some other approach, I will take complete one node in one string -- try to get the measures and unit -- then based on that I will produce other tags and then I will concatenanate the nodes.. please tell me how do you find this approach.... If possible give me some outline of this approach in terms of syntax...
pranavkulkarni is offline   Reply With Quote
Old Jul 6, 2012   #472
psycore
Member
 
2nd Dan Black Belt
Join Date: Feb 2010
Posts: 267



For the regular expression part, see here, here or here (including next page). The last one is the best but also most complicated.

Code:
first = true
-- complete saves the whole text we want to write
complete = ""
-- tmp contains one node
tmp = ""
for line in input:lines() do
    --[[ pseudo code
        if line containes "equipment"
            -- if we find it the first time, there's no node to be saved yet
            if first then first = false
            else
                -- attach the node
                complete .. tmp .. "\n"
                -- change the node to centimeter
                in tmp replace meter with centimeter
                in tmp replace "<size>(%d+)" with "<size>%100" -- regular expression
                -- attach that part
                complete .. tmp .. "\n"
                -- change the node to milimeter
                in tmp replace centi with mili
                in tmp replace "<size>(%d+)" with "<size>%10" -- regular expression
                -- attach again
                complete .. tmp .. "\n"
            end
        -- if line is part of node attach to tmp
        elseif line doesn't contain catalog and line doesn't contain xml then
            tmp .. line .. "\n"
        else
            -- no part of node, directly attach to complete
            complete .. line .. "\n"
        end
    ]]--
end
-- output and close
input:close()
output:write(complete)
output:flush()
output:close()
This assumes that you have a input and a output variable which handle the files.
psycore is offline   Reply With Quote
Old Jul 7, 2012   #473
Vlad84
Junior Member
 
Brown Belt
Join Date: Jan 2012
Posts: 4



Help. How to make a long shadow (longer)?
Translated with http://translate.google.com/
Vlad84 is offline   Reply With Quote
Old Jul 7, 2012   #474
psycore
Member
 
2nd Dan Black Belt
Join Date: Feb 2010
Posts: 267



Sorry, I don't understand.
psycore is offline   Reply With Quote
Old Jul 9, 2012   #475
pranavkulkarni
Junior Member
 
Join Date: Jul 2012



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...
pranavkulkarni is offline   Reply With Quote
Old Jul 9, 2012   #476
psycore
Member
 
2nd Dan Black Belt
Join Date: Feb 2010
Posts: 267



assuming that the content of the .xml file is stored in a variable called "text":
Code:
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>".
psycore is offline   Reply With Quote
Old Jul 9, 2012   #477
pranavkulkarni
Junior Member
 
Join Date: Jul 2012



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
pranavkulkarni is offline   Reply With Quote
Old Jul 9, 2012   #478
psycore
Member
 
2nd Dan Black Belt
Join Date: Feb 2010
Posts: 267



gfind(text, regex) returns a function which each time it is called returns the next occurrence of regex in text. So for example:
Code:
 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:
Code:
-- %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:
Code:
 -- 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):
Code:
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.
psycore is offline   Reply With Quote
Old Jul 11, 2012   #479
pranavkulkarni
Junior Member
 
Join Date: Jul 2012



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!
pranavkulkarni is offline   Reply With Quote
Old Jul 18, 2012   #480
J0Y
Member
 
4th Dan Black Belt
Join Date: Jan 2011
Posts: 492
Clan: NAO



is there a way to get/set each bodypart's rotation?
❀~❋~❀~❋~❀~❋~❀~❋~❀
J0Y is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:06 PM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
ragdoll fighting game physics fighting game ragdoll fighting physics funmotion joints martial arts karate pc mac free game turn based game