Missing function random_range in Mac game maker
#1
Posted 04 December 2011 - 06:30 PM
#2
Posted 04 December 2011 - 08:26 PM
return argument0+random(argument1-argument0);If you name this script random_range, you get the exact same functionality.
GameGeisha
#3
Posted 04 December 2011 - 08:34 PM
random_range() is new to GM8.1, but GM4Mac doesn't have it yet. You can create one yourself, though:
return argument0+random(argument1-argument0);If you name this script random_range, you get the exact same functionality.
GameGeisha
Thank you so much!
#4
Posted 04 December 2011 - 09:02 PM
random_range() is new to GM8.1, but GM4Mac doesn't have it yet. You can create one yourself, though:
return argument0+random(argument1-argument0);If you name this script random_range, you get the exact same functionality.
GameGeisha
Now I have another problem, after I wrote this: random_range = return argument0+random(argument1-argument0); and then started the game an error came which said this:
COMPILATION ERROR in Script: random_range
Error in code at line 1:
random_range = return argument0+random(argument1-argument0);
at position 14: Variable name expected.
#5
Posted 04 December 2011 - 09:08 PM
Interesting behaviours.
Edited by YellowAfterlife, 04 December 2011 - 09:08 PM.
#6
Posted 04 December 2011 - 09:14 PM
return argument0+random(argument1-argument0);
Then you can call it as though it was a built-in function:
random_percentage = random_range(0, 100);
Defining scripts and calling them in this fashion is a basic technique that should stick.
GameGeisha
#7
Posted 04 December 2011 - 09:23 PM
No, that's not how it's done. The script should contain just the return statement. The assignment statement does not belong in there.
return argument0+random(argument1-argument0);
Then you can call it as though it was a built-in function:random_percentage = random_range(0, 100);
Defining scripts and calling them in this fashion is a basic technique that should stick.
GameGeisha
Ok thanks but one last question I did everything you told me but when I put this code
age = random_range (0, 20);
show_message(age);
It shows nothing in the dialog box when I start the game, it shows nothing is blank.....
#8
Posted 04 December 2011 - 09:28 PM
random_range() returns a real value, while show_message() expects a string. Passing a real value into a function that expects a string argument is not valid. To make this valid, you need to use string() to turn the result into a string:
age = random_range(0, 20); show_message(string(age));
GameGeisha
#9
Posted 04 December 2011 - 09:33 PM
First of all, you should turn the option that displays errors back on. Don't chicken out of problems caused by your coding. Let GM inform you to the best of its ability, and you should take an active role in fixing them.
random_range() returns a real value, while show_message() expects a string. Passing a real value into a function that expects a string argument is not valid. To make this valid, you need to use string() to turn the result into a string:age = random_range(0, 20); show_message(string(age));
GameGeisha
Thanks and sorry for the nuisance
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











