The variables GlobalsVariables.high_score and GlobalsVariables.life_score were both zero?

  • Edited

YES-- both. Even with Lifescore tested up to 128.

Screen shot below shows: Despite HUD showing high_score 22, the debug showed saved as zero.

..
Just to explain: I even added buttons to test manually saving and loading score .
Because there was some conflict upon returning to this transition page (between levels) _onready would reload the old high-score, negating any advance made in level.

  • Edited

NOW BACK TO MAIN TOPIC- SAVING TO WP DB:

I FOUND THE FOLLOWING SNIPPETS (AND ADAPTED BETWEEN THEM any missing code):
I HAVE INCLUDED PERHAPS SOME DUPLICATION FOR USERNAME - BECAUSE I WOULD LIKE TO DISPLAY WP USERNAME IN GAME PLAY:
-TO SEE WHICH IS BETTER- CAN WE REFINE THIS ...

GDScript:

`var dataText = "testData"
var score = 10
var dict = {name: dataText,score: 10 }
var http_request = HTTP Request.new()
add_child(http_request)

func _ready():
http_request.request_finished.connect( _on_request_finished)

func _on_button_pressed():
http_request.request(
"https://mysite/wp_json/wp/v2/users/me"
)
_make_post_request(myurl, dict, false)
print("data sent")

func _make_post_request(url, data_to_send, use_ssl):
var query = JSON.print(data_to_send)
var headers = ["Content-Type: application/json"]
$HTTPRequest.request(url, headers, use_ssl, HTTPClient.METHOD_POST, query)

func _on_request_finished(result, error_string):
if result == OK
var data = JSON.parse( http_request.get_data().get_string())
var username =data["username"]
$Label.text = "username: " +username
else:
$Labe.text = "Error = " +error_string`
.

THEN SERVER_SIDE PHP Script:

<?php
include 'DatabaseConfig.php' ;
$json = file_get_contents('php://input');
$_POST = json_decode($json);
//echo $_POST;
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$name = $_POST['name'];
$score = $_POST['score']
$Sql_Query = "insert into game_test (Name, score) values ('$name', '$score')";
if(mysqli_query($con,$Sql_Query)){
echo 'Data Submit Successfully';
}
else{
echo 'Try Again';
}
mysqli_close($con);
?>

  • Toxe replied to this.
    4 days later
    • Edited

    Hi Toxe,
    Yes of course.
    As part of it, WP core files are pretty secure against SQL injection. On top of that, on WP I have Wordfence plugin- it seems to stop an incredible number of attacks ~ over 50 attacks a day are blocked! They all try to log in fake IDs . Upon failing with frustration, some try & send me loaded email links- malware, ransomeware, which I recognize with mouse-hover, and delete. Also WP verifies if the user is email verified & logged in; and user permissions attributes.

    But you are right, I think with HTTP requests on Godot we need more. (which is another reason why I say to use internal php query rather than http requests on the database.)

    Reading through the 1st Link you suggested, I'm a little lost- They suggest using "mysqli_real_escape_string() function.", but I don't see it in their example code. How /where do I write this?

    Also, WP script is different syntax. I'm compiling code which I will put up soon for comment.

    7 days later
    • Edited

    The 1st thing , I need to capture (and display) the user name. Let's try the local machine 1st. The following code from tuts i'm following gives me an error:- What should I add? The Get statement?as in get_data().get_string()) . Any complete tuts on this?

      redrc The string you're passing to parse_string() is not valid json.

      redrc why you need json to parse a string into json? its like cooking egg on a sun and watering it with a garden hose so that it wont burn.