[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  sqlite variables
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

sqlite variables

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Posted by Miloh   (4 posts)  [Biography] bio
Date Sun 20 Nov 2011 04:56 AM (UTC)  quote  ]

Amended on Sun 20 Nov 2011 05:02 AM (UTC) by Miloh

Greetings all,

I am attempting to create a mob database with sqlite. The db is very simple - I just have two fields: mobname and roomname. Both fields go into the sqlite db. The problem is that one of the variables (MyRoom) is going into the db as the variable name itself. I am guessing this is a syntax thing? Any insight would be most appreciated. Here is what I am using:

   match="^You get (.*) gold coin? from the dead body of (.*)\.$"
  <send>local MyRoom
--RoomName set by another trigger elsewhere that captures roomname.
MyRoom = GetVariable("RoomName")

--ensure vars are correct
Note ("%2 is in ",MyRoom)

--begin db stuff

DatabaseOpen ("mobs", GetInfo (66) .. "mobs.db", 6)

-- insert a record
DatabasePrepare ("mobs", "INSERT INTO mobtable (mobname, roomname) VALUES ('%2','MyRoom')")  --&gt; returns 0 (SQLITE_OK)
DatabaseStep ("mobs")   -- returns 101 (SQLITE_DONE)
DatabaseFinalize ("mobs")  -- returns 0 (SQLITE_OK)
DatabaseClose ("mobs")  -- close it </send>

And when I check the db, the "%2" or mobname goes in as correctly. But, for roomname, I get "MyRoom".

Thanks much in advance!
[Go to top] top

Posted by Fiendish   USA  (1,006 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sun 20 Nov 2011 05:12 AM (UTC)  quote  ]

Amended on Sun 20 Nov 2011 05:14 AM (UTC) by Fiendish

VALUES ('%2','MyRoom')

I'm not sure what you expect that to do other than what is happening.

Perhaps you want instead
"INSERT INTO mobtable (mobname, roomname) VALUES ('%2','"..MyRoom.."')"

[Go to top] top

Posted by Miloh   (4 posts)  [Biography] bio
Date Reply #2 on Sun 20 Nov 2011 05:26 AM (UTC)  quote  ]
Hi Fiendish, you are the man!! That worked like a charm. Thank you very much. I had a feeling it was something like that. I did fail to mention that I tried everything I could think of with that pesky variable... Double quotes, no quotes at all, a ".." before the variable, a dollar sign...

Anywho, again, thank you :)

[Go to top] top

Posted by Fiendish   USA  (1,006 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Sun 20 Nov 2011 05:36 AM (UTC)  quote  ]

Amended on Sun 20 Nov 2011 05:41 AM (UTC) by Fiendish

Values for %1,%2,etc get mapped into place by MUSHclient before the Lua code gets sent to the script parser. That's the only reason you can use %2 in the way you did without breaking the query string apart into chunks (and which is why people need to wrap them in quotation marks to compare the values with strings). But MyRoom is just a Lua variable containing a string. In order to get the value from MyRoom you have to treat it as a variable and not just like some letters, which means pulling it outside of the string and using concatenation to merge the parts together.

You had
DatabasePrepare("mobs", "a_string")
when you needed
DatabasePrepare("mobs", "first_part_of_the_string"..your_variable.."the_rest_of_the_string")

[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum

[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.


Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]