GameMaker: Studio

GameMaker: Studio

View Stats:
DaBears Jun 26, 2016 @ 5:50pm
Is it possible to multiply a function?
I want to use a instance_create function but instead of typing it out say 5 times i want to do something like instance_create * 5. Is this possible? I plan on spawning an unlimited amount of instances so there is no way I can do this without multiplying the function by a variable unless you know a way.
< >
Showing 1-6 of 6 comments
Albcatmastercat Jun 26, 2016 @ 5:55pm 
I think if you did...
repeat(4) { instance_create() }
it would work. Try it.
DaBears Jun 26, 2016 @ 6:00pm 
Originally posted by Albcatmastercat:
I think if you did...
repeat(4) { instance_create() }
it would work. Try it.
thanks
GproKaru Jun 30, 2016 @ 2:46am 
Using repeat(x) with larger variables could see stuttering when used excessively. If you want to do it an alternate way, you can use a for loop.

var r = 1000;
for(i=0; i<r; i+=1;)
{
instance_create();
}

^^^ Basically, if the object isn't overly scripted, Game maker would semelessly create a 1000 of them with this method.
Last edited by GproKaru; Jun 30, 2016 @ 2:47am
kris40k Jul 8, 2016 @ 5:37pm 
Originally posted by GproKaru:
Using repeat(x) with larger variables could see stuttering when used excessively. If you want to do it an alternate way, you can use a for loop.

var r = 1000;
for(i=0; i<r; i+=1;)
{
instance_create();
}

^^^ Basically, if the object isn't overly scripted, Game maker would semelessly create a 1000 of them with this method.

Do you know what the difference is in the implementation of repeat() and a for loop? I'm curious why there would be a performance impact, or is this just some practical experience or similar.
Fern Jul 9, 2016 @ 11:10pm 
repeat() and for() are the same. The repeat() loop is actually faster if you are just running code that doesn't need to be incremented. If you are incrementing a number, use a for() loop.

If you need 10 instances in the same position, you should use a repeat() loop.
libertea Jul 11, 2016 @ 11:55pm 
There are 4 loops in Gamemaker: for, while, do while, and repeat. (Or just recursion)
While[docs.yoyogames.com] loops are just for loops that keep executing until the if part is false.
For[docs.yoyogames.com] loops are while loops that allow you to set and manage a variable in a consice and readable manner.
for (set a variable; the if part; do something to the variable)
For example
for (var i = 0; i < 10; i += 1) show_debug_message(string(i));
Would produce 0 - 10 in the debug console.
Do[docs.yoyogames.com] while (or do until) is just a while loop that is garunteed to run at least once.
Repeat[docs.yoyogames.com] loops are just blocks of code that repeat a given amount of times. As Seabass mentioned, repeat loops are fastest, so use those if you have no need for an iterator.

EDIT: I missed a loop, the with loop. With[docs.yoyogames.com] loops are loops that execute code within all instances of a specified object.
Last edited by libertea; Jul 12, 2016 @ 12:00am
< >
Showing 1-6 of 6 comments
Per page: 1530 50

Date Posted: Jun 26, 2016 @ 5:50pm
Posts: 6