Hi guys, currently I am using GMS 1.4, I'm still working on a survival project right now. I am performing a monkey with the following actions: if it is near the banana it will run to get the banana to eat, if it is close to the main character it will follow the main character, and if it is from 7pm (19h) to 5am It will sleep and then wake up. The code I am currently doing is basically like below, but is it not working while sleeping? which means from 7pm to 5am she still can't sleep, I don't understand what's wrong, hope someone can help me. Thank you.
Create events:
Step Events:
Create events:
GML:
Sleeping=0; state = STATE_IDLE; Eating=0;
Code:
if instance_exists(oBanana) and Sleeping =0 /// monkey will follow the banana
{
if distance_to_object(oBanana) <=150
{
state = STATE_FOLLOWEAT;
Eating=1;
}else
{
state = STATE_IDLE;
Eating=0;
}
}else if (instance_exists(objPlayerCharacter)) and Eating=0 and Sleeping=0 /// monkey will follow the main character
{
if (point_distance(x, y, objPlayerCharacter.x, objPlayerCharacter.y) <= 150)
{
state = STATE_FOLLOWPLAYER;
}else if (state == STATE_FOLLOWPLAYER)
{
state = STATE_IDLE;
}
}else if Sleeping=0
{
if ( oMapController.hour >= 19 && oMapController.hour <= 23) ) || ( oMapController.hour >= 0 && oMapController.hour <= 5) ) /// monkey will sleep
{
state = STATE_SLEEP;
Sleeping=1;
}else
{
state = STATE_IDLE;
Sleeping=0;
}
}
Last edited: