Jump to content


Photo

Are variable functions fast?


  • Please log in to reply
7 replies to this topic

#1 ihato

ihato

    Destroyed

  • Banned Users
  • 739 posts
  • Version:GM8

Posted 21 October 2011 - 02:07 PM

I want to create a variable FROM a string, and I know execute_string is a bit slow. So I thought of using variable functions, but how fast are they?

If they are just as fast as execute_string, then its pointless to use those functions.

EDIT: Typing mistake

Edited by ihato, 21 October 2011 - 03:42 PM.


#2 mads2194

mads2194

    GMC Member

  • GMC Member
  • 368 posts
  • Version:Unknown

Posted 21 October 2011 - 03:00 PM

I want to create a variable with a string


You what? ... I don`t really understand what you meant...

As in: str = "Ahoy me hearties, thou shalt be a string"
or as in: execute_string("str = 'Ahoy me hearties, thou shalt be a string' ")
Edit: or maybe you meant this ( variable_local_get(name) ) type of function which are useless in my opinion

Edited by mads2194, 21 October 2011 - 03:02 PM.

  • 0

#3 GameGeisha

GameGeisha

    GameGeisha

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

Posted 21 October 2011 - 03:23 PM

You really shouldn't use variable_*() functions. Though faster than execute_string(), they are considerably slower than just using the identifier. They also tend to reinforce the poor novice habit of equating identifiers with strings.

This is especially true if you intend to continue using GM for longer periods outputs. It is a known fact that variable_*() functions will be thrown out of future versions starting with GM4HTML5 in order to facilitate obfuscated and compiled outputs. Start living without it now.

GameGeisha

Edited by GameGeisha, 21 October 2011 - 03:24 PM.

  • 0

#4 mads2194

mads2194

    GMC Member

  • GMC Member
  • 368 posts
  • Version:Unknown

Posted 21 October 2011 - 03:48 PM

You really shouldn't use variable_*() functions. Though faster than execute_string(), they are considerably slower than just using the identifier. They also tend to reinforce the poor novice habit of equating identifiers with strings.

This is especially true if you intend to continue using GM for longer periods outputs. It is a known fact that variable_*() functions will be thrown out of future versions starting with GM4HTML5 in order to facilitate obfuscated and compiled outputs. Start living without it now.

GameGeisha


I sometimes use variale_local_exists for objects which have instance specific variables, like moving platforms: not all of them move at the same speed or as much
  • 0

#5 GameGeisha

GameGeisha

    GameGeisha

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

Posted 21 October 2011 - 04:21 PM


You really shouldn't use variable_*() functions. Though faster than execute_string(), they are considerably slower than just using the identifier. They also tend to reinforce the poor novice habit of equating identifiers with strings.

This is especially true if you intend to continue using GM for longer periods outputs. It is a known fact that variable_*() functions will be thrown out of future versions starting with GM4HTML5 in order to facilitate obfuscated and compiled outputs. Start living without it now.

GameGeisha


I sometimes use variale_local_exists for objects which have instance specific variables, like moving platforms: not all of them move at the same speed or as much

This still doesn't justify using variable_local_exists(). I've worked with moving platforms that vary in specs without even thinking about using that function. What are you actually doing that warrants using it?

GameGeisha
  • 0

#6 mads2194

mads2194

    GMC Member

  • GMC Member
  • 368 posts
  • Version:Unknown

Posted 21 October 2011 - 04:34 PM

This still doesn't justify using variable_local_exists(). I've worked with moving platforms that vary in specs without even thinking about using that function. What are you actually doing that warrants using it?

GameGeisha


I check if the speed and length variables have been declared in the instance creation event so that I won`t try to work with undeclared variables and get an error.

Edited by mads2194, 21 October 2011 - 04:35 PM.

  • 0

#7 xshortguy

xshortguy

    GMC Member

  • Global Moderators
  • 4188 posts
  • Version:GM:Studio

Posted 21 October 2011 - 04:48 PM

I check if the speed and length variables have been declared in the instance creation event so that I won`t try to work with undeclared variables and get an error.


This can be alleviated through better planning. In fact, let the variable throw an error so then you know that it may need to be looked at; this will help prevent future bugs.
  • 0

#8 GameGeisha

GameGeisha

    GameGeisha

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

Posted 21 October 2011 - 09:03 PM


This still doesn't justify using variable_local_exists(). I've worked with moving platforms that vary in specs without even thinking about using that function. What are you actually doing that warrants using it?

GameGeisha


I check if the speed and length variables have been declared in the instance creation event so that I won`t try to work with undeclared variables and get an error.

You don't need variable_local_exists() here, just use inheritance.

First you take the moving platform object and strip out the declarations for speed and length, that'll provide the basis from which to work on. Then you specify the speed and length by doing one of the following:
1. Create the instance in the room using the room editor. Then right-click on it and select Creation Code. Set the values for speed and length there.
2. If a particular speed-length setup is common, you can consider creating a new object inheriting from that basic object. Create a new blank object, then select the basic object as its parent. Afterwards, put this in the creation event:
speed = 5;
length = 72;
event_inherited();
3. Create the instance on the fly using instance_create(), then set the speed and length from there:
var inst;
inst = instance_create(100, 100, obj_basic_moving_platform);
inst.speed = 5;
inst.length = 72;

This will work well into the future of GM, methods using variable_*() functions won't.

GameGeisha
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users