darrck Posted February 3, 2021 Share Posted February 3, 2021 Hi, I'm working on a script to count and display the number of laps made by different players in a race. I rapidly found out that the one programing board was infact multiple as it was run localy by all the players (when I start it I'm the only one who sees it as started) and therefore I tried using a database to sync them all up. I have an array full of ints and I'm trying to write functions that would help me get those in and ou the database (The problem only accurs when I try to get my arrays back) my script allways gets shutdown by the game for some reason (it's not a script error but a cpu overload or smth). so there's the code if annyone got some time to lose trying to help me: function insertIntArrayToDB(startKey,array) i = 1 while i <= #array do db.setIntValue(i+startKey-1, array[i]) i = i + 1 end end function getIntArrayFromDB(startKey) --we supose there's an unused key after the array i = startKey arrayToFill = {} while db.hasKey(i) do table.insert(arrayToFill,db.getIntValue(i)) i=i+1 end return arrayToFill end array={2,4,8,16,32,128} insertIntArrayToDB(0,array) backArray = getIntArrayFromDB(0) system.print(backArray) --btw printing arrays in chat doesn't work Link to comment Share on other sites More sharing options...
Hazard0814 Posted February 3, 2021 Share Posted February 3, 2021 tbh, this is one scenario where a third party server running a lua client would come in handy. I'd pay a few dollars to keep SOME lua things running myself if I had them. Link to comment Share on other sites More sharing options...
fiddlybits Posted February 4, 2021 Share Posted February 4, 2021 4 hours ago, darrck said: while db.hasKey(i) do db.hasKey(i) returns 0 or 1 rather than true/false. In lua 0 is a true value, so this while loop never ends. It should work if you change this line to: while db.hasKey(i) == 1 do ... Link to comment Share on other sites More sharing options...
darrck Posted February 8, 2021 Author Share Posted February 8, 2021 On 2/4/2021 at 2:19 AM, fiddlybits said: db.hasKey(i) returns 0 or 1 rather than true/false. In lua 0 is a true value, so this while loop never ends. It should work if you change this line to: while db.hasKey(i) == 1 do ... damn didn't see that one coming .... btw i found another way to deal with that but my race software broke anyways (2 players wen trough at near the exact same time and editing a db while reading it never goes well ....) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now