Hello people,
Just wondering how you slice up data retrieved from a mysql database and how I can use that information in the game by setting them as variables.
Here’s the code
function getAchieve()
{
var createuser_url = “******/resources/get_achieve.php” + “?username=” + user + “&password=” + pass + “&level=” + levelTest;
var cu_ get = new WWW(createuser_url);
yield cu_get;
if(cu_get.error) {
print("There was an error checking admin: " + cu_get.error);
}
else
{
var data = cu_get.text;
var words = data.Split(","[0]);
words[0] = starAchieve;
words[1] = deathAchievement;
words[2] = ultimate;
Debug.Log("WBESKSJSJ"+starAchieve);
}
}
PROBLEM : The problem is in the data.Split as my Debug.Log() shows up when it is place before this piece of code and not after!
Any advice would be much appreciated thanks. Or any advice on how to properly split the download data.
BTW - starAchieve, ultimate, deathAchievement are all variables set at top of script.
Ok boys and girls here is a php call which involves a relational database in mysql. Data is processed into an array then split up and converted to floats.
PHP:
<?php
require 'connection.php';
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$query = "SELECT users.*, level1.* FROM users INNER JOIN level1 ON users.user_id = level1.user_id
WHERE users.username = '$username' AND users.password = '$password'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num_results = mysql_num_rows($result);
for($i = 0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo $row['star'] . "," . $row['death'] . ",";
}
UNITY SCRIPT -
private var deathAchievement;
private var starAchieve;
private var ultimate;
function getAchieve()
{
var createuser_url = "http://localhost:8888/*******/resources/get_achieve.php" + "?username=" + user + "&password=" + pass + "&level=" + levelTest;
var cu_get = new WWW(createuser_url);
yield cu_get;
if(cu_get.error) {
print("There was an error checking admin: " + cu_get.error);
}
else
{
data = cu_get.text;
var values : String[] = data.Split(","[0]);
var v1 : float = parseInt(values[0]);
var v2 : float = parseInt(values[1]);
var v3 : float = parseInt(values[2]);
}
May be some help to some people!