Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Thu Jun 12, 2008 2:14 pm   

Help understanding error in lua + event
 
In the event "onZoneChange" with the params "Start" and "End" (the starting and ending zone), i have this code:
Code:

#call @mysql_select("SELECT `mobId`, CONCAT(`short`, CHAR(124), `long`, CHAR(124), `level`, CHAR(124), `keywords`) AS `data` FROM `tbl_Mobs` WHERE `areaID` = '"$End"'", "mobId", "data", MobDataTemp)


And that function is defined as
Code:

--Get A Temp Var Name
temp = 'dbtemp'
--Check If A Temp Var Is Specified
if zs.numparam > 3 then
  --And Update It If There Is One
  temp = zs.param(4)
end
--Clear The Temp Variable
zs.exec(string.format("#var %s {}", temp))

--Include The LUASQL DLL
require("luasql.mysql")
--Reference A LUASQL MYSQL Object
env = assert(luasql.mysql())
--Connect To The Database
con = assert(env:connect("cmud", "cmud", "cmud", "localhost"))

--Execute The Select Query
cur = assert(con:execute(zs.param(1)))

--Define Index
i = 1
--Define The Results Table
results = {}

--Fetch The Results
results[i] = cur:fetch({}, "a")

--Loop Through The Results
while results[i] and (not zs.aborted) do
  --Add The Result To The Temp Variable (Replace Quotes With A Substitute)
  zs.exec(string.format("#addkey %s {%s} {%s}", temp, results[i][zs.param(2)], string.gsub(results[i][zs.param(3)],'\"', '%%char\(34\)')))
  --zs.var.temp.results[i][zs.param(2)] = results[i][zs.param(3)]
  --Increment The Index
  i = i + 1
  --Fetch The Results
  results[i] = cur:fetch({}, "a")
end

--Close Our Cursor
cur:close()
--Close The Connection
con:close()
--Close The MYSQL Object
env:close()

--Return True
return 1


Now occasionally, it evaluates zs.param(1) or something before i get a chance to execute the query, and i get mysql returning an error that "0" is not a valid query.
This only happens occasionally, so I'm struggling to figure out why. Any ideas on what might be causing this, or a better way to access luasql from both z/cscript and lua would be great.
_________________
The Drake Forestseer
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Thu Jun 12, 2008 2:19 pm   
 
Some further info, it's not exactly replicatable. Just closed cmud and reopened and it worked. But once it happens, it will keep happening in that spot.

IE, last session, it would happen when i moved down from a 2-room zone into a much larger zone (every time), yet when i portalled back into the 2-room zone (which still fired the event), it wouldn't happen
_________________
The Drake Forestseer
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net