Jump to content


Photo

What is wrong with my script?


  • Please log in to reply
12 replies to this topic

#1 taras8

taras8

    GMC Member

  • New Member
  • 13 posts

Posted 15 April 2012 - 11:11 AM

Hi, i am trying to make script in gm:html5 which check if file exist online or not.
Does anybody know what is wrong with this script.

if file_exists(http_get(www.google.com/robots.txt))
room_goto(NextRoom)
else
show_message("No file found.");

I get this error:

COMPILATION ERROR in code action
Error in code at line 1:
if file_exists(http_get(www.google.com/robots.txt))
at position 16: Unknown function or script: http_get

Edited by taras8, 15 April 2012 - 06:51 PM.

  • 0

#2 azcodon

azcodon

    GMC Member

  • GMC Member
  • 201 posts
  • Version:Unknown

Posted 16 April 2012 - 02:06 AM

FILE function get structuring follow: name_function(argument).argument is a varible or a constant,its not a function
your code : http_get(www.google.com/robots.txt) <<<its function
you do: file_exits('a') or file_exists(b);b="name_file"
and you have really been known the basic GML: the function of (http_get(www.google.com/robots.txt)) is getting on server.The function of (file_exists) is getting on client
  • 0

#3 Destron

Destron

    GMC Member

  • GMC Member
  • 1222 posts
  • Version:GM:Studio

Posted 16 April 2012 - 05:52 AM

The proper way to do this would be in the event you want to check if the file exists just use:
http_get(www.google.com/robots.txt);

This will return some information stored in a ds_map. The you must process the return in the Asynchronous event, so add an Asynchronous HTTP event and put in this:

data = ds_map_find_value(async_load,"http_result"); //Get the returned result and store it as a variable.

if data == 200 //The file was found
{
    room_goto(NextRoom); // go to next room
}
else 
{
//Do whatever you want if the file is not there.
}

200 is simply the HTTP status of a file that exists. If it did not exists it would be 404. HERE is all the status codes you can check for.

Edited by Destron, 16 April 2012 - 06:00 AM.

  • 0

#4 taras8

taras8

    GMC Member

  • New Member
  • 13 posts

Posted 16 April 2012 - 10:50 AM

The proper way to do this would be in the event you want to check if the file exists just use:

http_get(www.google.com/robots.txt);

This will return some information stored in a ds_map. The you must process the return in the Asynchronous event, so add an Asynchronous HTTP event and put in this:

data = ds_map_find_value(async_load,"http_result"); //Get the returned result and store it as a variable.

if data == 200 //The file was found
{
    room_goto(NextRoom); // go to next room
}
else 
{
//Do whatever you want if the file is not there.
}

200 is simply the HTTP status of a file that exists. If it did not exists it would be 404. HERE is all the status codes you can check for.


Thanks for help! I am real noob so i still have some problem with making it work. i always go to room3. Do you know what i did wrong?
Posted Image
  • 0

#5 Destron

Destron

    GMC Member

  • GMC Member
  • 1222 posts
  • Version:GM:Studio

Posted 16 April 2012 - 04:32 PM

Either Room 3 is named NextRoom, or you don't have a room named NextRoom and instead of crashing going to room 3 is a result.

If you literally wanted to go to the next room then you should be using room_goto_next() instead of room_goto(NextRoom);

Also, one thing to watch for is that the Asynchronous event will not wait for a return to continue so if the server is being really slow it may not be getting thee request fast enough. So if you think that may be an issues, you may want to check if 'data' has a value other than 0 before proceeding.

Edited by Destron, 16 April 2012 - 04:38 PM.

  • 0

#6 taras8

taras8

    GMC Member

  • New Member
  • 13 posts

Posted 16 April 2012 - 06:12 PM

Either Room 3 is named NextRoom, or you don't have a room named NextRoom and instead of crashing going to room 3 is a result.

If you literally wanted to go to the next room then you should be using room_goto_next() instead of room_goto(NextRoom);

Also, one thing to watch for is that the Asynchronous event will not wait for a return to continue so if the server is being really slow it may not be getting thee request fast enough. So if you think that may be an issues, you may want to check if 'data' has a value other than 0 before proceeding.

I have tried room_goto_next() and it get same problem. I also tried use timelines, so there will be time to load robot.txt file but it does not helped.But when i try to run game in windows (not in browser) i get this error:

Posted Image

So is there something wrong with this http_get function?

Edited by taras8, 16 April 2012 - 06:13 PM.

  • 0

#7 azcodon

azcodon

    GMC Member

  • GMC Member
  • 201 posts
  • Version:Unknown

Posted 17 April 2012 - 01:18 AM

basic of GML please
if you use ds_map function.first make a=ds_map_create();ds_map_write_string(string,a).....
your code dont need use ds_map
try this:
a=0
a=http_get(www.google.com/robots.txt);
event step:
if a!=0 room_goto(your room)
  • 0

#8 taras8

taras8

    GMC Member

  • New Member
  • 13 posts

Posted 17 April 2012 - 05:38 AM

basic of GML please
if you use ds_map function.first make a=ds_map_create();ds_map_write_string(string,a).....
your code dont need use ds_map
try this:
a=0
a=http_get(www.google.com/robots.txt);
event step:
if a!=0 room_goto(your room)

This code make that i always go to "your room", even if i am disconnected from internet.

Edited by taras8, 17 April 2012 - 12:14 PM.

  • 0

#9 azcodon

azcodon

    GMC Member

  • GMC Member
  • 201 posts
  • Version:Unknown

Posted 17 April 2012 - 11:47 AM

:))
event create:
global.a=0
event mouse or keyboard.....:
global.a=http_get(www.google.com/robots.txt);
event step:
if global.a!=0 room_goto(yourroom)


i can not help you each detail,you must own search it :))
  • 1

#10 taras8

taras8

    GMC Member

  • New Member
  • 13 posts

Posted 17 April 2012 - 04:39 PM

:))
event create:
global.a=0
event mouse or keyboard.....:
global.a=http_get(www.google.com/robots.txt);
event step:
if global.a!=0 room_goto(yourroom)


i can not help you each detail,you must own search it :))


Did you tested this code in gm:html5?
This whole day i am trying get this code to work with different ways but it just wont work(((
  • 0

#11 Destron

Destron

    GMC Member

  • GMC Member
  • 1222 posts
  • Version:GM:Studio

Posted 17 April 2012 - 06:16 PM

I will upload an example for you soon
  • 0

#12 taras8

taras8

    GMC Member

  • New Member
  • 13 posts

Posted 17 April 2012 - 06:27 PM

I will upload an example for you soon

Thanks)
  • 0

#13 hobbitbabes

hobbitbabes

    GMC Member

  • GMC Member
  • 173 posts
  • Version:GM:Studio

Posted 25 August 2013 - 09:28 PM

old thread i know but i am desperate :/

 

i understand how to check if a file exists but when i check and the staus code is 200 is there some code to be able to download that file and save it to the sd card of an android device??


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users