///wait(ms)
/*
Pauses code execution for given amount of milliseconds
1000 = 1 second
DISCLAIMER: Don't use this for anything more than debugging!
Normally, this type of function pauses the code. But this code traps the cpu in
an indefinite loop, which is very resource intensive and if you delay for too long
(11 seconds or more on windows 10), the OS will start assuming your app is dead
*/
var pauseStamp = current_time;
while pauseStamp+argument0 > current_time
{
// Waste CPU
}
That is missing the point of the GMS event model. Doing what you suggest just hangs the game, stopping everything from doing anything at all for all instances, until the time has elapsed (except perhaps music running in a different thread).So you could do this:
Well that is also what delay would do. Music in another thread is a good point thoughThat is missing the point of the GMS event model. Doing what you suggest just hangs the game, stopping everything from doing anything at all for all instances, until the time has elapsed (except perhaps music running in a different thread).
Yes, as mentioned in the comments of the function.You're not only wasting CPU, you're causing the program to hang. And if it hangs too long, the operating system might flag it as a crash. That's why they removed the sleep() function when Studio came out.
This is just about never what people want or expect when they ask the question. They only want the code within the block to be delayed for some time, not everything else that makes up the game.Well that is also what delay would do. Music in another thread is a good point though
Well that's subjectiveThis is just about never what people want or expect when they ask the question.
From some visual studio documentationhttps://randomnerdtutorials.com/why-you-shouldnt-always-use-the-arduino-delay-function said:delay() is a blocking function. Blocking functions prevent a program from doing anything else until that particular task has completed. If you need multiple tasks to occur at the same time, you simply cannot use delay().
https://www.theengineeringprojects.com/2013/10/how-to-add-delay-in-microsoft-visual.html said:You should take much care in using this delay because this delay simply makes your software to sleep and thus while the delay is in process, your software won't do any other task
2.https://c-for-dummies.com/blog/?p=69 said:C:void delay(int milliseconds) { long pause; clock_t now,then; pause = milliseconds*(CLOCKS_PER_SEC/1000); now = then = clock(); while( (now-then) < pause ) now = clock(); }
3.https://www.geeksforgeeks.org/time-delay-c/ said:C:void delay(int number_of_seconds) { // Converting time into milli_seconds int milli_seconds = 1000 * number_of_seconds; // Storing start time clock_t start_time = clock(); // looping till required time is not achieved while (clock() < start_time + milli_seconds) ; }
I am aware it's not a good practice but if you need a wait function, that will do it.https://www.sitepoint.com/delay-sleep-pause-wait/ said:JavaScript:function sleep(milliseconds) { const date = Date.now(); let currentDate = null; do { currentDate = Date.now(); } while (currentDate - date < milliseconds); } console.log("Hello"); sleep(2000); console.log("World!");
In the context of writing a program in GMS it is useless. It is not why people ask about a pause function or keyword in GML. Really. I'm going to predict that what @HerkusX is asking about fits all other past topics on this board on the same subject, and the answer has never been to completely halt the execution of the game.if you need a wait function, that will do it.
This is subjective. If you want to throw a program together really quickly to test something, then it can be useful. It could save you 2 minutes of your time.In the context of writing a program in GMS it is useless.
Quite possibly, I don't think anyone disagrees on the idea that wait() is not a good longterm solution.I'm going to predict that what @HerkusX is asking about fits all other past topics on this board on the same subject, and the answer has never been to completely halt the execution of the game.
You guys make it sound really complicated, all i want is to do some pauses in the game. For instance :This is subjective. If you want to throw a program together really quickly to test something, then it can be useful. It could save you 2 minutes of your time.
Quite possibly, I don't think anyone disagrees on the idea that wait() is not a good longterm solution.
But it's also possible that other people may come across this topic from google, looking for a wait() function specifically in GMS. And there it is, if they want it. At their peril.
I'm just not sure how to set the time on alarm ( when will it execute). Ill try reading the manual.
alarm[0] = room_speed * 3; //Whatever code is in the alarm[0] event will execute in three seconds.
// CREATE EVENT
alarm[0] = room_speed * 3; // Alarm is set to 3 seconds, since the room_speed value is the number of steps in one second
direction = 0;
speed = 0.5;
// ALARM[0] EVENT
direction -= 180; // Reverse the direction
alarm[0] = room_speed * 3; // reset the alarm so it is called again
Sorry, but that's not what was asked for. It was move an unspecified distance and time (I have no idea how to put 3 blocks into time or distance)., then don't move for 3 seconds, then move again in the opposite direction.And that's it! Now the instance will move in a direction for 3 seconds, then turn around and move in the other direction for 3 seconds, etc..
See? All this debate about stalling the game has even ME muddled.Sorry, but that's not what was asked for. It was move an undetermined distance and time., then don't move for 3 seconds, then move again in the opposite direction.
// CREATE EVENT
move = true; // This variable will control if the instance moves or not
alarm[0] = 5;
// STEP EVENT
if move == true
{
x += 2; // "move" is true, so move the instance!
}
// ALARM[0]
if move == true
{
move = false;
alarm[0] = room_speed; // Setting the alarm to roomspeed means that the instance will pause for 1 second (60 frames)
}
else
{
move = true;
alarm[0] = 5; // Setting the alarm to 5, means the instance will move for 5 frames
}
// CREATE EVENT
horizontal_speed = 2;
move = true; // This variable will control if the instance moves or not
// STEP EVENT
if move == true
{
x += horizontal_speed; // "move" is true, so move the instance!
}
if (x < 20 || x > 400) // just some sample condition of course, better values based on instances, room extent, or view boundaries may be more desirable
{
move = false;
alarm[0] = 3 * room_speed;
}
// ALARM[0]
horizontal_speed = -horizontal_speed;
move = true;
x += 5;
x += 5;
x += 5;
x += 5;
wait(3);
x += 5;
wait(3);
x += 5;
wait(3);
// Where wait is a magic function that blocks for n seconds