• Adding string to table
    7 replies, posted
I'm trying to add a entity as a tables key, and its 'description' as it's value. However, when I do this, the description/value only inserts one word of the string. [lua] TS.DescriptedProps[tr.Entity] = { Description = "Testing 123" } [/lua] [code] ] rcon lua_run print( PrintTable( TS.DescriptedProps ) ) > print ( PrintTable ( TS.DescriptedProps ) )... Entity [301][prop_physics]: Description = Testing [/code] As you can see, it only inserts the first word of the value in. Is there another way?
That's weird, works for me. Don't see why you're doing print(PrintTable(table)) tho, you can't just do PrintTable(table).
Why wont it work
If you're running the code using the rcon command in console, you may be the victim of some funky command parsing semantics. Try using single quotes (') rather than double quotes or try running the code using an actual .lua file.
TS.DescriptedProps[tr.Entity] = 'yo man' Seems to work, but TS.DescriptedProps[tr.Entity] = arg[1] doesn't, even though arg[1] is a string.
Assuming you enter this into the console: [code] lolcommand Testing 123 [/code] The value of arg would be: [lua] { [1] = "Testing", [2] = "123", } [/lua] You can either write some code to merge these into one string (try [u]table.concat(arg, " ")[/u]). Or, you can use quotes to make it a single argument when entering it into the console: [code] lolcommand "Testing 123" [/code] You're a victim of funky command parsing here, not strange Lua semantics.
[QUOTE=Deco Da Man;21183944]Assuming you enter this into the console: [code] lolcommand Testing 123 [/code] The value of arg would be: [lua] { [1] = "Testing", [2] = "123", } [/lua] You can either write some code to merge these into one string (try [u]table.concat(arg, " ")[/u]). Or, you can use quotes to make it a single argument when entering it into the console: [code] lolcommand "Testing 123" [/code] You're a victim of funky command parsing here, not strange Lua semantics.[/QUOTE] What do you mean 'victim'. And are you saying it's only happening to me?
[QUOTE=H0rsey;21184673]What do you mean 'victim'. And are you saying it's only happening to me?[/QUOTE] I mean that you're a 'victim' of your own ignorance of the command parsing semantics of the Source engine's console. Not that this is a bad thing - you just haven't learnt how it works yet.
Sorry, you need to Log In to post a reply to this thread.