- Home /
MySQL Funktionen Hilfe
Yo !! I'm new in MySQL and i want to do something. In my game i'm calculating the EXP and the level from the complete EXP. But i want to calculate the Stats depending from the Level in my Database. I know there are functions and procedures. but i don't know what syntax to use i don't even know how i can get changes of variables or variables in general...
in short i need an SQL code where i can catch the change of a variable and change other variables from different tables with a specified formula... i just need a dummy code so i can see what to do.
i hope you can help this would be really awesome !!
PS: I'm using MySQL if this is important.
Answer by VesuvianPrime · Sep 17, 2014 at 07:47 PM
If I understand you correctly, you want the MySQL server to tell all clients when a value changes in a table.
This was a big problem on a business application I was working on last year. My MySQL isn't great, but as I understand it there is no real way to push changes from the database like that.
Your best bet is to have an intermediate Unity server that pushes changes to clients, and occasionally polls the database where necessary.
This is more work to implement, but actually acts as a form of load balancing and will make your game far more scalable. Furthermore, it may potentially act as an extra layer of security.
no thats not what i wanted. i mean when someone somewhere changes a value in a table the function should regognize it and change other values in it's own database. the change don't have to be recognized the point is that it's there and changes other values
i just want the server to do work i don't want to do in my program with SQL commands because the more i do in my program the slower it is. because its a free server i'm using its not the fastest ^-^
I'm afraid that doesn't really clarify what you are trying to accomplish.. I assume your current setup is something along the lines of:
Game instance that communicates with http server ->
HTTP server that uses php to send mysql requests to database ->
$$anonymous$$YSQL database
Could you elaborate on your setup and what you are trying to accomplish?
okay in long words: I have a Unity Game which communicates with my Database through the Devart Namespace. When you defeat an enemy the character gets some EXP In my Database from the Exp a Level should be calculated. and from the level the status is calculated... you know atk def etc... i know there are functions and procedures in the database. i just want the database to calculate my status values you know? thats everything. i got a table where all data for a character lies... EXP Level AT$$anonymous$$ and DEF points and if the EXP points change the database should calculate level AT$$anonymous$$ and DEF by a formula i give you know? damn i hate this language ^-^
Why not simply calculate those values within your game before sending the update to the database?
$$anonymous$$ySQL isn't really that kind of a program$$anonymous$$g language - it is more like a syntax that tells the database what values to update or retrieve.
The normal way would be to have whatever is calling the mysql commands be what takes care of calculating all the necessary data and the database doesn't do anything with this information other than store it.
$$anonymous$$y suggestion would be to create a function within your game that calculates all the necessary level, status and atk values depending on the exp variable and then send all this info to the database in one query.
Pseudo Code:
void CalculatePlayerLevel (int exp) {
// calculate all the values you need here
int level = exp * 5;
int atk = level / 2;
// now update these values in DB for player with the id 14 (or whatever)
string myQuery = "UPDATE player_stats SET exp="+exp+", level="+level+" WHERE player_id=14";
// ...
}
Is there any reason for you not to do it this way?
yeah yeah i know this would be easier for me too but if i know how to do it i can use it for other procedures in my code. the point is to send as less as possible database requests... at the moment every .cs document has at least 5 database communication codes... read.. write... create... whatever and if there's a way to just delete them and do the update work in my Database the program would be much faster
the other way would be to start the mysql queries in a Coroutine but this isn't as easy as it sounds because there are many things that can just be done after the coroutine is done so i have to make a coroutine for every single case of database connection !!
Your answer
Follow this Question
Related Questions
Unity MySQL Database? 0 Answers
Login from database in unity 0 Answers
Store data in MySQL DB 4 Answers
My die function gets called without me asking it. 1 Answer
A node in a childnode? 1 Answer