ShiVa3D
testing for variable types [SOLVED]
All about the StoneScripttesting for variable types
by HaggisMcHaggis » 26 Jul 2012, 06:36
Hi All,
I currently have a table that stores different variable types. Is there a way of testing what kind of variable is stored when looping through it? Eg In my table, I have 1 string, 1 number and another table. How would I go about doing this in LUA script?
I currently have a table that stores different variable types. Is there a way of testing what kind of variable is stored when looping through it? Eg In my table, I have 1 string, 1 number and another table. How would I go about doing this in LUA script?
- HaggisMcHaggis
- Fresh Boarder

- Posts: 15
Re: testing for variable types
by freezer » 28 Jul 2012, 11:53
you can test using a few lua functions...
http://www.lua.org/manual/5.1/manual.html/#pdf-tonumber
tonumber()
tostring()
type()
*** not tested
http://www.lua.org/manual/5.1/manual.html/#pdf-tonumber
tonumber()
tostring()
type()
*** not tested
- freezer
- Expert Boarder

- Posts: 155
Re: testing for variable types [SOLVED]
by Fraser » 30 Jul 2012, 17:21
LUA has "type" function, which returns a string containing the type of the passed var:
http://www.lua.org/pil/2.html
What you want to do is not possible in stonescript which is a subset of LUA. This may change in Shiva2.
You will have to use seperate tables for each type, or you will have to interleave types in a known order.
http://www.lua.org/pil/2.html
What you want to do is not possible in stonescript which is a subset of LUA. This may change in Shiva2.
You will have to use seperate tables for each type, or you will have to interleave types in a known order.
Fraser,
http://www.silicondroid.com
http://www.silicondroid.com
Re: testing for variable types
by HaggisMcHaggis » 11 Aug 2012, 02:35
Thanks for that
I've solved it using different tables.
- HaggisMcHaggis
- Fresh Boarder

- Posts: 15
5 posts
• Page 1 of 1
