Thread: Combining tabled strings
Status: Alpha
Brought to you by:
cwalther
|
From: James C. W. <jfc...@ya...> - 2011-11-29 22:05:29
|
I'm trying to combine the values of several variables into a single literal string for checking equality. In this case the subject is an ingame computer into which the player must type commands. I've got everything to work perfectly except for this one issue: local execute = ""..keypress[1]..""..keypress[2]..""..keypress[3].. ""..keypress[4].. ""..keypress[5].. ""..keypress[6].. ""..keypress[7].. ""..keypress[8].. ""..keypress[9].. ""..keypress[10].. "" Each tabled variable represents either a typed character or a space, depending on what the player has typed, all combined into a single string. if execute == "map" then The purpose of this is to check if the player typed "map" and if so direct further action. However it seems that Pipmak does not interpret and break down this combined string in the same way it would if the string were the filename of a patch or the text of a drawtext() operation, which is what I was hoping for. Instead I receive an "unexpected symbol near "if" error. Thanks, James CW |
|
From: Christian W. <cwa...@gm...> - 2011-11-30 20:50:27
|
James C. Wilson wrote:
> local execute = ""..keypress[1]..""..keypress[2]..""..keypress[3]..
> ""..keypress[4].. ""..keypress[5].. ""..keypress[6].. ""..keypress[7]..
> ""..keypress[8].. ""..keypress[9].. ""..keypress[10].. ""
>
> if execute == "map" then
Works for me. By the way, you don't need all these empty strings - this
works too:
local execute = keypress[1]..keypress[2]..keypress[3]..
keypress[4]..keypress[5]..keypress[6]..keypress[7]..keypress[8]..
keypress[9]..keypress[10]
And if you want to save some typing, or handle variable-sized lists, a
shorter version is
local execute = table.concat(keypress)
(see http://www.lua.org/manual/5.0/manual.html#5.4 )
> I receive an "unexpected symbol near "if" error.
That suggests that there is something wrong with what comes before the
"if" - Lua is not expecting an "if" there, but something that completes
whatever comes before.
-Christian
|
|
From: James C. W. <jfc...@ya...> - 2011-12-08 23:01:49
|
Sorry for taking so long to respond... So actually that "if" problem was just a typo on my part, sorry. However, a new spanner is in the works: Pipmak still doesn't seem to translate the concatenation into the literal string needed. It just prints out the standard "Unused key 13 pressed" and does nothing when I press enter (the trigger for this whole thing). Note that if I replace the string "HELP" in the query with the raw concatenation, pipmak finds equality and it works.(But of course that doesn't help, cause that just makes Pipmak see anything the player types as being correct.) Here's the chunk that seems to be the problem: elseif key == pipmak.key_return then local execute = table.concat(keypress) if execute == "HELP" then pipmak.schedule(2, function() preScreen = pipmak.newimage(460, 340) preScreen:color(100, 33, 248) screen:setimage(preScreen) preScreen:drawtext(50, 90, ">:_" .. table.concat(keypress) .. "", "../fonts/Daniel_J_-_Deka.otf", 18, pipmak.left) preScreen:drawtext(50, 120, "VISITOR LOG \nMAP \nCOMMUNICATION \nEMERGENCY", "../fonts/Daniel_J_-_Deka.otf", 18, pipmak.left) screen:setimage(preScreen) end) return true else return false end Thanks, James CW --- On Wed, 11/30/11, Christian Walther <cwa...@gm...> wrote: From: Christian Walther <cwa...@gm...> Subject: Re: Combining tabled strings To: pip...@li... Date: Wednesday, November 30, 2011, 3:48 PM James C. Wilson wrote: > local execute = ""..keypress[1]..""..keypress[2]..""..keypress[3].. > ""..keypress[4].. ""..keypress[5].. ""..keypress[6].. ""..keypress[7].. > ""..keypress[8].. ""..keypress[9].. ""..keypress[10].. "" > > if execute == "map" then Works for me. By the way, you don't need all these empty strings - this works too: local execute = keypress[1]..keypress[2]..keypress[3].. keypress[4]..keypress[5]..keypress[6]..keypress[7]..keypress[8].. keypress[9]..keypress[10] And if you want to save some typing, or handle variable-sized lists, a shorter version is local execute = table.concat(keypress) (see http://www.lua.org/manual/5.0/manual.html#5.4 ) > I receive an "unexpected symbol near "if" error. That suggests that there is something wrong with what comes before the "if" - Lua is not expecting an "if" there, but something that completes whatever comes before. -Christian ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d _______________________________________________ Pipmak-Users mailing list Pip...@li... news://news.gmane.org/gmane.games.devel.pipmak.user https://lists.sourceforge.net/lists/listinfo/pipmak-users |
|
From: Christian W. <cwa...@gm...> - 2011-12-09 12:09:05
|
James C. Wilson wrote:
> However, a new spanner is in the works: Pipmak still doesn't seem to
> translate the concatenation into the literal string needed. It just
> prints out the standard "Unused key 13 pressed" and does nothing when I
> press enter (the trigger for this whole thing). Note that if I replace
> the string "HELP" in the query with the raw concatenation, pipmak finds
> equality and it works.(But of course that doesn't help, cause that just
> makes Pipmak see anything the player types as being correct.)
>
> Here's the chunk that seems to be the problem:
>
> elseif key == pipmak.key_return then
> local execute = table.concat(keypress)
> if execute == "HELP" then
> pipmak.schedule(2, function()
> preScreen = pipmak.newimage(460, 340)
> preScreen:color(100, 33, 248)
> screen:setimage(preScreen)
> preScreen:drawtext(50, 90, ">:_" .. table.concat(keypress) .. "",
> "../fonts/Daniel_J_-_Deka.otf", 18, pipmak.left)
> preScreen:drawtext(50, 120, "VISITOR LOG \nMAP \nCOMMUNICATION
> \nEMERGENCY", "../fonts/Daniel_J_-_Deka.otf", 18, pipmak.left)
> screen:setimage(preScreen)
> end)
> return true
> else
> return false
> end
I see nothing wrong with that - evidently keypress is something
different than {"H", "E", "L", "P"}, but since you don't show what it is
(or how you compose it), there isn't enough information to say anything.
Try inserting a "pipmak.print(execute)" to see what's there, or if
keypress is a global variable, you can examine it using the Lua command
line (enter "keypress" and press return, then use the crosshairs on the
result to open the table inspector). (Unfortunately
"pipmak.print(keypress)" isn't helpful, as it doesn't print the contents
of the table.)
By the way, you don't need to "screen:setimage(preScreen)" twice, once
is sufficient - it's still the same image even after you draw into it.
-Christian
|
|
From: James C. W. <jfc...@ya...> - 2012-01-11 01:23:18
|
Looks like my response a couple weeks ago never got through for some reason, sorry. Resending. So actually that "if" problem was just a typo on my part, sorry. However, a new spanner is in the works: Pipmak still doesn't seem to translate the concatenation into the literal string needed. It just prints out the standard "Unused key 13 pressed" and does nothing when I press enter (the trigger for this whole thing). Note that if I replace the string "HELP" in the query with the raw concatenation, pipmak finds equality and it works.(But of course that doesn't help, cause that just makes Pipmak see anything the player types as being correct.) Here's the chunk that seems to be the problem: elseif key == pipmak.key_return then local execute = table.concat(keypress) if execute == "HELP" then pipmak.schedule(2, function() preScreen = pipmak.newimage(460, 340) preScreen:color(100, 33, 248) screen:setimage(preScreen) preScreen:drawtext(50, 90, ">:_" .. table.concat(keypress) .. "", "../fonts/Daniel_J_-_Deka.otf", 18, pipmak.left) preScreen:drawtext(50, 120, "VISITOR LOG \nMAP \nCOMMUNICATION \nEMERGENCY", "../fonts/Daniel_J_-_Deka.otf", 18, pipmak.left) screen:setimage(preScreen) end) return true else return false end Thanks, James CW --- On Wed, 11/30/11, Christian Walther <cwa...@gm...> wrote: >From: Christian Walther <cwa...@gm...> >Subject: Re: Combining tabled strings >To: pip...@li... >Date: Wednesday, November 30, 2011, 3:48 PM > > >James C. Wilson wrote: >> local execute = ""..keypress[1]..""..keypress[2]..""..keypress[3].. >> ""..keypress[4].. ""..keypress[5].. ""..keypress[6].. ""..keypress[7].. >> ""..keypress[8].. ""..keypress[9].. ""..keypress[10].. "" >> >> if execute == "map" then > >Works for me. By the way, you don't need all these empty strings - this >works too: > > local execute = keypress[1]..keypress[2]..keypress[3].. > keypress[4]..keypress[5]..keypress[6]..keypress[7]..keypress[8].. > keypress[9]..keypress[10] > >And if you want to save some typing, or handle variable-sized lists, a >shorter version is > > local execute = table.concat(keypress) > >(see http://www.lua.org/manual/5.0/manual.html#5.4 ) > >> I receive an "unexpected symbol near "if" error. > >That suggests that there is something wrong with what comes before the >"if" - Lua is not expecting an "if" there, but something that completes >whatever comes before. > > -Christian > > >------------------------------------------------------------------------------ >All the data continuously generated in your IT infrastructure >contains a definitive record of customers, application performance, >security threats, fraudulent activity, and more. Splunk takes this >data and makes sense of it. IT sense. And common sense. >http://p.sf.net/sfu/splunk-novd2d >_______________________________________________ >Pipmak-Users mailing list >Pip...@li... >news://news.gmane.org/gmane.games.devel.pipmak.user >https://lists.sourceforge.net/lists/listinfo/pipmak-users > |
|
From: Christian W. <cwa...@gm...> - 2012-01-11 22:47:17
|
James C. Wilson wrote: > Looks like my response a couple weeks ago never got through for some reason, sorry. Resending. Your message did go through, and I responded to it here: http://thread.gmane.org/gmane.games.devel.pipmak.user/793/focus=798 -Christian |