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.
private UnityEngine.Object queueLock = new UnityEngine.Object();
public void ...(..) {
if (something) {
lock (queueLock){
//critical action (like setting a global variable)
}
}
}
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.