Pancakes Posted April 9, 2012 Share Posted April 9, 2012 Would that work out okay? I am looking at this simple lua info and I am just wondering whether this is the right path to go. Right now I use arrays for everything in my lua code including a finite state system implementation. Where I basically just say... --State System stateSys={} stateSys[1] = {name = "Break", switch = "false"} stateSys[2] = {name = "CamSwitching", switch = "true"} stateSys[10] = {name = "In Battle", switch = "true"} stateSys[11] = {name = "Battle Mode", switch = "active"} stateSys[12] = {name = "Base Damage Cal", switch = "set to nil"} stateSys[13] = {name = "Friend or Foe", switch = "friend"} stateSys[21] = {name = "pa_commandprompt", switch = "disabled"} stateSys[22] = {name = "Count?", switch = "count"} It's the same for the weapons, characters, monster data... Everything in my lua code is structured around manipulated arrays like this. It's not elegant but it works and it runs fast. I tried fancy loops but I just ended up slowing things down. Well anyway, everything is running and working fine except I don't have a dynamic inventory system that is capable of sorting itself and being sorted by the player in game. Is the table.insert command the right way to go for building something like this into my array laden code? If so, does anyone have tips on how to use it effectively so that I can have a sortable inventory? Thanks Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3 Link to comment Share on other sites More sharing options...
Daimour Posted April 10, 2012 Share Posted April 10, 2012 Is the table.insert command the right way to go for building something like this into my array laden code? Yes. table.insert() works with arrays only. It increases array length by 1. It doesn't do anything with no-number indexes. table.insert(array, object) is the same (if you have no nil values inside array) as array[#array + 1] = object For sorting table you can use table.sort() function. Quote Link to comment Share on other sites More sharing options...
Rick Posted April 10, 2012 Share Posted April 10, 2012 @Pancakes, those are really "tables" not arrays. Note that you can use anything for the "index" or "key". It can be nice sometimes to use strings as the key, but you can even use another table if you want. The below link shows how you can sort tables in various different ways. http://lua-users.org...LibraryTutorial For an inventory I might look at using a string name of the item and the value could be the count (all depending on how you work your inventory though, stacking, splitting stacks, etc). inventory["wood"] = 50 for example When I'm working in Lua I almost always found it easier to use strings as the keys for many different things. Also, in Lua tables (or you calling them arrays) is basically how one works in Lua. Pretty much everything revolves around tables (array) so you are fine Quote Link to comment Share on other sites More sharing options...
Pancakes Posted April 11, 2012 Author Share Posted April 11, 2012 thanks, I'll let you know how it turns out Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3 Link to comment Share on other sites More sharing options...
Benton Posted April 11, 2012 Share Posted April 11, 2012 Maybe MySQL would also work...? Just an idea... Quote Windows 7 Professional 64 bit, 16 gigs ram, 3.30GHz Quad Core, GeForce GTX 460 one gig, Leadwerks 2.5, Blender 2.62, Photoshop CS3, UU3D Link to comment Share on other sites More sharing options...
Josh Posted April 12, 2012 Share Posted April 12, 2012 Would that work out okay? I am looking at this simple lua info and I am just wondering whether this is the right path to go. Right now I use arrays for everything in my lua code including a finite state system implementation. Where I basically just say... --State System stateSys={} stateSys[1] = {name = "Break", switch = "false"} stateSys[2] = {name = "CamSwitching", switch = "true"} stateSys[10] = {name = "In Battle", switch = "true"} stateSys[11] = {name = "Battle Mode", switch = "active"} stateSys[12] = {name = "Base Damage Cal", switch = "set to nil"} stateSys[13] = {name = "Friend or Foe", switch = "friend"} stateSys[21] = {name = "pa_commandprompt", switch = "disabled"} stateSys[22] = {name = "Count?", switch = "count"} It's the same for the weapons, characters, monster data... Everything in my lua code is structured around manipulated arrays like this. It's not elegant but it works and it runs fast. I tried fancy loops but I just ended up slowing things down. Well anyway, everything is running and working fine except I don't have a dynamic inventory system that is capable of sorting itself and being sorted by the player in game. Is the table.insert command the right way to go for building something like this into my array laden code? If so, does anyone have tips on how to use it effectively so that I can have a sortable inventory? Thanks That seems a little complex, when you can just do stuff like this: stateSys.break = false stateSys.CamSwitching = true Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Pancakes Posted April 19, 2012 Author Share Posted April 19, 2012 You're right, but when I started making this script I didn't know that. And I also set it up so that any numbered switch can do any number of different things and then I can view dubug text that tells what it's doing. Why? Lack of experience. I was just making it up as I went along. I was using my experience with CryEngine Flowgraphs and Blender Logic Bricks to come up with the design for it though. My entire script is just a bunch of text nodes like in a flowgraph, that you designate with set state commands just like in Blender GE, which is how I see it now. Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.