GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2010-06-17 00:12:43

flexaplex
Member
Registered: 2008-12-11
Posts: 72

get_value

From my gmc topic: http://gmc.yoyogames.com/index.php?showtopic=475256

Expand//get_value(Original Message, Default Value, Invalid Message)

var user_val, user_dig, val_mes;
user_dig = "";  val_mes = argument0;

while !(string_digits(user_dig) == user_dig && string_length(user_dig) > 0)
{
  user_val = get_string(val_mes, argument1);
  if (string_char_at(user_val, 1) == "-" || string_char_at(user_val, 1) == "+")
  {
        user_dig = string_replace(string_delete(user_val, 1, 1), ".", "");
  }
  else
  {
        user_dig = string_replace(user_val, ".", "");
  }
  val_mes = argument2;
}
return real(user_val);

This script does not cover exponential format so I decided not to call it get_real. Torigara did write an alternative using exps if you prefer that:
http://gmc.yoyogames.com/index.php?showtopic=466011

Offline

#2 2010-06-17 14:08:19

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: get_value

Nice, pretty slick error checking. This topic sure comes around a lot. It really should be built into Game Maker.


Abusing forum power since 1986.

Offline

#3 2010-06-17 14:56:01

flexaplex
Member
Registered: 2008-12-11
Posts: 72

Re: get_value

Yes it really should be included, I wish I remembered to ask when GM8 was being made (though I'm doubting it would have been made). I've seen it being asked a lot recently which is why I decided to make a script for it.

Offline

Board footer

Powered by FluxBB