Jump to content

Lua rollover himself on bigger scripts!(?)


XetaQuake

Recommended Posts

Hey all.

I get a problem, and i hope anybody can confirm this problem too, or knows a workaround etc.

Okay, let me beginning:

i'm working with SQLLite databases for a MTA Lua-Script. It works all fine, there is but one not repeatable bug i get sometimes.

If some more peaple are playing, sometimes lua rollover himself (Thats my thesis)! It's like lua are not executing a line correctly. This happened sometimes when a player are launching a script-part that let's a SQLLite Row updating - but only on rows they containing a specific value. So, i let lua search all SQLLite Rows in a DB Table, using for i, blabla in ipairs ( allBlabla ) do .... i think you know what i mean. But sometimes lua doesn´t find this specific value on one of the rows - but this value a still exists! I think its because lua jumps over this row sometimes.

Is this known, got anybody experience with such a problem already? Or is there any workaround - for example to "slack off" lua a little bit during search a value in tables?

Hope anybody answers.

Thanks for pay attention! :)

XetaQuake

Link to comment

So I guess you mean that it should return data, but it doesn't seem to RETURN everything, or to output/process everything?

Also, could you show us an example? So the code you use, or a comparable one which might do the same?

And ofcourse, it might be a good idea to tell us your MTA version. ( DP2? Nightly? Nightly version?)

Link to comment

Hey Gamesnert :)

And ofcourse, it might be a good idea to tell us your MTA version. ( DP2? Nightly? Nightly version?)

Oh yes, sorry, forgetting that.

I'm still scripting with DP2.3, and i'm using DP2.3 too :wink:

So I guess you mean that it should return data, but it doesn't seem to RETURN everything, or to output/process everything?

Lua sould write the player nick and username in a specific row. But sometimes, it doesn't happens! It's to buy properties, so when a player start buying it, they need to pay the properties but after that the properties is not owned by them SOMETIMES.

Also, could you show us an example? So the code you use, or a comparable one which might do the same?

Sure, here is a example (doesn´t want to past everyting here, so this part is trimmed a little bit):

  
function functionName( pickup ) 
local nickName = getClientName ( myPlayer ) 
local userAccount = getClientAccount ( myPlayer ) 
local userName = getAccountName ( userAccount ) 
local x, y, z = getElementPosition ( pickup ) 
local sqlTableSelect = executeSQLSelect( "SQLTableName", "specificValue1, specificValue2, specificValue3" ) 
    for v, sqlTableSelectAll in ipairs ( sqlTableSelect ) do 
        executeSQLUpdate ( "SQLTableName", "nick = '" .. nickName .. "', user = '" .. userName .. "'", "sqlTableSelect[v][1] = '" .. x .. "' AND sqlTableSelect[v][2] = '" .. y .. "' AND sqlTableSelect[v][3] = '" .. z .. "'") 
    end 
end 
 addEventHandler( "onPlayerPickupUse", getRootElement(), functionName ) 
  

Thats not the same code as my, but the "problem zone" a nearly the same: the for tables let lua rollover from time to time. I'm not sure with this, but i want to know if this is a possible cause. My script are to big and to branched to post it, you would not understood it fastly.

XetaQuake

Link to comment
        executeSQLUpdate ( "SQLTableName", "nick = '" .. nickName .. "', user = '" .. userName .. "'", "sqlTableSelect[v][1] = '" .. x .. "' AND sqlTableSelect[v][2] = '" .. y .. "' AND sqlTableSelect[v][3] = '" .. z .. "'") 

I'm pretty sure that the sqlTableSelect[v][2] stuff you're doing there is not valid SQL. :P

Also, Lua does not behave erroneously or "roll over". It's at version 5.1; it's pretty safe to say that by now the authors have ironed out any bugs in something as basic as ipairs. What _can_ happen is one of these things:

1) Something in your code is causing an error, interrupting the script and preventing the row from even being inserted into the database. Watch out for errors in debugscript.

2) Some part of your code takes too long to execute (i.e. several seconds), causing MTA to abort it. Again look in debugscript.

3) There is a mistake in your code because of which the code that adds the row is not run; or it adds the row, but with wrong data.

If you can't find the cause of a bug it is indeed often tempting to blame the language. This may be valid for obscure, badly-maintained languages, but that's not the case here. Try to think rationally about possible causes instead :).

Link to comment

Thanks for answer and bring light in this. The funny think is: I found already a possible reason why this problem appears. Tomorrow i test it with our team, and see if that cause is true what i'll think - after that, i will answer

I'm pretty sure that the sqlTableSelect[v][2] stuff you're doing there is not valid SQL. :P

No, it works realy good. Okay, possible they is one or two little typing error in this example-function - i writes it just for this thread. On my original script, its called sqlTableSelect[2] (too by creating the table), but this phpBB board doesn´t showed though it was in a

 tag, rofl 

So, see you!

Xeta

Link to comment

I really have my doubts about your SQL query. sqlTableSelect is a *Lua* variable, which SQLite does _not_ know about. The query in your example code would only work if you had actual columns named "v" and "sqlTableSelect" in your table, and where "sqlTableSelect" would also contain a multidimensional array per row (which I'm not even sure is supported by SQLite or is even in the SQL standard at all).

I would really check for SQL error messages in the server console if I were you.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...