- Home /
if(SQL SELECT) { do something; } ????
I need to do an action based on a mySQL SELECT result... for example if result = 1 do something and change register to 0. If result = 0, do another thing and change register to 1. The thing is that multiple people will using the game, so, how can I be sure that, between the time I did the sql query and the time I do the action and change the value, someone else hasn't modified the value already?
EDIT: Javascript language ;) EDIT 2: This is solved only with transactions? the first query is a select and the second one is an update.
Answer by softrare · Mar 26, 2012 at 02:02 PM
I hope you program in C# ^^
private UnityEngine.Object queueLock = new UnityEngine.Object();
public void ...(..) {
if (something) {
lock (queueLock){
//critical action (like setting a global variable)
}
}
}
this should put you on the right track :)
Answer by jakovd · Mar 26, 2012 at 02:11 PM
This is actually not a Unity question, but here is a suggestion for solving your problem anyway. This is a common problem which is solved by using transactions. Google "mysql transaction". Your problem is similar to a problem of withdrawing money from account, which is often used in transaction examples.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
'NetworkTranformChild' problem 1 Answer
Network.isServer / isClient not working 1 Answer
Help|sync movement in multiplayer 1 Answer
[UNET] NetworkTransform - Synch Rotation - none - error 0 Answers