Combining tabled strings

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Combining tabled strings

James C. Wilson

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

Reply | Threaded
Open this post in threaded view
|

Re: Combining tabled strings

cwalther
Administrator
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



Reply | Threaded
Open this post in threaded view
|

Re: Combining tabled strings

James C. Wilson
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 <[hidden email]> wrote:

From: Christian Walther <[hidden email]>
Subject: Re: Combining tabled strings
To: [hidden email]
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
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users
Reply | Threaded
Open this post in threaded view
|

Re: Combining tabled strings

cwalther
Administrator
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



Reply | Threaded
Open this post in threaded view
|

Combining tabled strings

James C. Wilson
In reply to this post by James C. Wilson




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 <[hidden email]> wrote:

From: Christian Walther <[hidden email]>
Subject: Re: Combining tabled strings
To: [hidden email]
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
[hidden email]
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users


Reply | Threaded
Open this post in threaded view
|

Re: Combining tabled strings

cwalther
Administrator
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

Reply | Threaded
Open this post in threaded view
|

Re: Combining tabled strings

James C. Wilson
Oh sorry--I resent the wrong message. I meant this one, which explains how I compile the input:

Here's node.lua. You asked how I put together the input, and it's just a table with ten slots,  each of which gets assigned a letter with each keystroke. I did check what pipmak.print(execute) brings up, and oddly enough it was "HELP", which is what it should be--but pipmak just doesn't see equality.




From: Christian Walther <[hidden email]>
To: James C. Wilson <[hidden email]>; Content creation for the Pipmak Game Engine <[hidden email]>
Sent: Wednesday, January 11, 2012 5:46 PM
Subject: Re: Combining tabled strings

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


node.lua (11K) Download Attachment