Help with your scripting

String Manipulation

String Manipulation

Postby Shando » 20 Mar 2013, 04:37

G'day again,

Are there any String Manipulation commands available (such as right, left, mid etc.)?

Also, how can I Tag/Name a spawned Entity with my own Tag rather than the automatically generated one (i.e. "octagon_13" rather than "Models_octagonS_x9993 # 26" )?

Regards

Shando
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: String Manipulation

Postby SolarPortal » 20 Mar 2013, 13:32

Are there any String Manipulation commands available (such as right, left, mid etc.)?

currently there is no skyline string manipulation library. We will have a look at implementing the commands such as erase, substr, etc.. (Basically a lua wrapper to std::string).

Also, how can I Tag/Name a spawned Entity with my own Tag rather than the automatically generated one (i.e. "octagon_13" rather than "Models_octagonS_x9993 # 26" )?

We shall implement a command to be able to do this for the next release.

:D
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: String Manipulation

Postby Shando » 20 Mar 2013, 21:25

Hi Guys,

Thanks for the reply, it's great to be on the ground floor and see an engine evolve 8-)

Basically a lua wrapper to std::string


Can't you just use the standard Lua commands such as string.find, string.len etc.? or are they too slow?

Regards

Shando

Edit: Scratch the bit about using standard LUA as the Lua commands already WORK :D :D

Code: Select all
function onClick( object_ID  )
   name = entity.getEntityName ( object_ID )
sky.lprint ( "ID = " .. object_ID )
sky.lprint ( "Name = " .. name )

   nTemp = string.find ( name, "#" )
sky.lprint ( "nTemp = " .. nTemp )
   name = string.sub ( name, nTemp + 2 )
sky.lprint ( "Name = " .. name )
end


The above generates:

ID = 75
Name = Models_octagonS_x6643 # 75
nTemp = 23
Name = 75

when run!!!!!
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: String Manipulation

Postby StarFire » 20 Mar 2013, 21:56

hehe saved us a job lol :lol:

Good find, we should add these to the api for reference. If you could kindly write them down so I can add them to our doxygen system, that would be great :D
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: String Manipulation

Postby Shando » 20 Mar 2013, 23:25

Hi NightHawk,

I have extracted the String commands (as well as the io and table ones) from the Lua Manual, and will send you an e-mail with the document.

I have only tested the following, but they all work OK, so the others should as well ;)

Code: Select all
string.find
string.sub
string.len

io.close
io.open
file:read

table.insert
table.getn (deprecated in 5.1)


I'll see if I can test a few more and check they're OK.

Regards

Shando

EDIT: Just be aware that:
Code: Select all
table.getn
has been replaced by the new (in 5.1) length operator:
Code: Select all
#
so when I used:
Code: Select all
for aa = 1, table.getn ( tTemp ) do
    table.insert ( tCSV, tTemp[aa] )
end
in my readCSV function, I should have used:
Code: Select all
for aa = 1, # ( tTemp ) do
    table.insert ( tCSV, tTemp[aa] )
end
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 4 guests

cron