Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Request / Listing] execute_string apparently can't read temp variables...  (Read 2734 times)

0 Members and 1 Guest are viewing this topic.
[Request / Listing] execute_string apparently ca...
« on: May 05, 2006, 03:23:20 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
I was just playing around with execute_string, and lo and behold, I found something out;

Code: [Select]
var temp;
temp = 20;
execute_string("if(temp > 15) {keyboard_wait();};");

I was just trying to test something out with execute string, and for some reason, execute_string doesn't seem to recognize temp as a variable. Is there a reason that this happens, or am I just a blabbering idiot? If not, does anyone know a way around this problem?
« Last Edit: February 24, 2012, 05:50:44 pm by Niek »
Logged

mit

Re: execute_string apparently can't read temp va...
« Reply #1 on: May 05, 2006, 03:36:22 pm »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
Interesting, I hadn't noticed that. It can read globals, and temp vars should be global...

Well, you could get around it by doing
Code: [Select]
var temp;
temp = 20;
execute_string(
   "var temp; temp="+string(temp)+";"+
   "if(temp > 15) {keyboard_wait();};"
   );
if ya know what I'm saying. I suppose the definition of the temp var is that it lasts until the end of the current peice of code, and so only within the current peice of code, and the execute_string must be classed as a different peice of code.
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: execute_string apparently can't read temp va...
« Reply #2 on: May 05, 2006, 05:47:48 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Chances are if the scripting language is any good, when you call execute_string its creating a new stack frame and execution context. Which would stop your from accessing locals as they would be on a different stack frame. Globals would probably be accessable as i believe gm keeps a globals outside the scripts stack.
Logged

mit

Re: execute_string apparently can't read temp va...
« Reply #3 on: May 05, 2006, 06:15:39 pm »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
Upon testing this, temp vars are not global or local, they're on their own little planet.

This doesn't work, as we know:
Code: [Select]
var temp;
temp="HELLO!"
execute_string("draw_text(x,y,temp);");

However, this does:
Code: [Select]
var temp;
temp="HELLO!"
with (all){draw_text(x,y,temp);}

And likewise this doesn't work at all:
Code: [Select]
var temp;
temp="HELLO!"
with (all){execute_string("draw_text(x,y,temp);");}

My solution above works;
Code: [Select]
var temp; temp='HELLO!';
execute_string("var temp; temp='"+string(temp)+"';"+"draw_text(x,y,temp);");

To investigate more, I ran this:
Code: [Select]
var temp;
temp="HELLO!"
if variable_global_exists(temp) draw_text(x,y,"'tis a global!");
if variable_local_exists(temp) draw_text(x,y,"'tis a local!");
Which sadly states that GM doesn't class them as either. This may just be the functions, but meh.

execute_string does work with local and global vars though, both
Code: [Select]
temp="HELLO!";
execute_string("draw_text(x,y,temp);");
and
Code: [Select]
global.temp="HELLO!";
execute_string("draw_text(x,y,global.temp);");
work.
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: execute_string apparently can't read temp va...
« Reply #4 on: May 05, 2006, 06:42:49 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
@Mit well actually they are local, as i tryed to explain in my previous post, locals can only be accessed by the stack frame is is defined in. As soon as you call execute_string it creates a whole new stack frame, and thus the previously declared variables can't be used.

Sorry if you dont understand what i mean, you need a basic grasp of how languages work to understand.
Logged

mit

Re: execute_string apparently can't read temp va...
« Reply #5 on: May 05, 2006, 07:39:35 pm »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
Nah, I do understand, it's just what I'm saying is, in GM usually with a local variable,
Code: [Select]
myvar=5;
with (another instance) { if (myvar<10) dosomething(); }
wouldn't work, as the variable would be local, and the control over the other object would be checking its own local variable myvar, which wouldn't be set. You have to refer to it as instancename.myvar, and so on. However, with the var command in GM, they span across the with thingy, so 
Code: [Select]
var myvar;
myvar=5;
with (another instance) { if (myvar<10) dosomething(); }
does work.
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: execute_string apparently can't read temp va...
« Reply #6 on: May 05, 2006, 07:42:10 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Might be that Var forces local behaviour, and undeclared variables are initilised as a global (or different).
Logged
Re: execute_string apparently can't read temp va...
« Reply #7 on: May 05, 2006, 07:58:08 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
Well, this is really weird. I've tried various combinations..but none seem to work.

If the execute_string can't read temp variables, maybe it is treated as a seperate script. Especially since you can declare temp variables within the method. I'm giong to do some more tests and see if I can find any information on the GMC about this.
Logged
Re: execute_string apparently can't read temp va...
« Reply #8 on: May 06, 2006, 12:03:26 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
does
Code: [Select]
var temp;
temp = 20;
execute_string("if("+string(temp)+" > 15) {keyboard_wait();};");
work?
Logged
Re: execute_string apparently can't read temp va...
« Reply #9 on: May 06, 2006, 12:29:20 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
The point isn't trying to fix this - the point is trying to understand why it happens. I guess execute_string has a differnet local scope than the script in which it is called.

But since this is true - it must be able to return. And according to this topic, my hypothesis is supported.

Lo and behold - it works! execute_string can return a value! Wow - talk about interesting.

http://gmot.chronic667.com/index.php?topic=1864.0

Look at J-Factor's post.
Logged
Re: execute_string apparently can't read temp va...
« Reply #10 on: May 07, 2006, 12:44:22 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
(Scooter: 20 trojans? Don't use IE! XD)

The issue is... I dont know. Maybe Mark didnt program execute_string to read temporary variables, but instead it checks for local and global. Other than that, No idea.
Logged
the a o d c
Re: execute_string apparently can't read temp va...
« Reply #11 on: May 07, 2006, 05:30:17 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
Yeah, I switched over to Firefox. IE is a !@#$%.

I actually solved this problem - look at the other link I posted.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.33 seconds with 61 queries.

anything