GM Version: Studio
Target Platform: Windows
Download: see code below
Links: n/a
Hi, i making a game where you can create levels and upload these levels for others.
So i have figured out easiest way to do this. I haven't seen this method anywhere when i was researching web for file uploading tutorials.
I do it for sending levels but you can also do it to pass single variables or json files with data.
Sooo first of all you need an ftp server. Select one, register etc.
Step 1: Go to your FTP file manager, create new file and call it WhateverYouWant.php
Step 2: Paste this code inside the file:
Step3: Now go to gamemaker and put this somewhere in key press or something like that (not in step)
And actually thats it. You sent ur file to ftp server.
You can pass as many variables you want by http_post_string, just remember to put "&" between them.
Step4: Do this in gamemaker to download file and get its content.
Some aditonal info:
If your file is JSON you can somehow reach its values without downloading a file (im not sure how, i think you can do it with http_request)
Other way of getting info from server is dooing something like this in ur php file: echo("info you want to get with gm") and then use http_get to get this value (look for gm manual to see how, you need to do stuff in async event)
Let me know if something is not right, i just wrote those codes now without checking if stuff works.
Target Platform: Windows
Download: see code below
Links: n/a
Hi, i making a game where you can create levels and upload these levels for others.
So i have figured out easiest way to do this. I haven't seen this method anywhere when i was researching web for file uploading tutorials.
I do it for sending levels but you can also do it to pass single variables or json files with data.
Sooo first of all you need an ftp server. Select one, register etc.
Step 1: Go to your FTP file manager, create new file and call it WhateverYouWant.php
Step 2: Paste this code inside the file:
Code:
<?php
$string = $_POST["string"]; //Get string from gamemaker
$fileName = $_POST["name"]; //Get name from gamemaker
$string2 = str_replace('<', '', $string); //Delete "<" symbols from string for safety
file_put_contents("uploads/".$fileName.".sav",$string2 ); //Create txt file from string you will send from gamemaker
?>
Code:
//Upload Levels
var q = file_text_open_read("upload.sav"); //Here put filename of file you want to send
var filestr = file_text_read_string(q);
file_text_close(q);
http_post_string("http://website.com/NameOfUrFile.php","string="+string(filestr)+"&fileName="+string(NAMEofFile))
You can pass as many variables you want by http_post_string, just remember to put "&" between them.
Step4: Do this in gamemaker to download file and get its content.
Code:
if keyboard_check_pressed(vk_down){
file = http_get_file("https://website.com/test.sav", "\Users\lukasz\AppData\Local\Bullet_Hell\down.zip"); //Here you need to put adress to file on ftp server (use +string(something) to select diffrent names) and second argument is for downloading. we need to save it as zip file because gamemaker dont allow to download txt or sav files.
}
if file_exists("down.zip"){ //Now just rename it to extension you want.
file_rename("down.zip","save.sav")
}
If your file is JSON you can somehow reach its values without downloading a file (im not sure how, i think you can do it with http_request)
Other way of getting info from server is dooing something like this in ur php file: echo("info you want to get with gm") and then use http_get to get this value (look for gm manual to see how, you need to do stuff in async event)
Let me know if something is not right, i just wrote those codes now without checking if stuff works.
Last edited by a moderator: