Jump to content


Photo

My AI take a decision once and never again...


  • Please log in to reply
4 replies to this topic

#1 RangerX

RangerX

    GMC Member

  • GMC Member
  • 923 posts
  • Version:GM8.1

Posted 12 March 2012 - 12:28 AM

Ok, I have an extremely simple NPC to wich you will talk to if you want. When that NPC isn't in discussion with the player, he's able to take the decision to walk left, right or stand there.
Now what happens with my current code is that he takes one decision and then never take another one.

The problem doesn't appear to be my switch (see down there). Well, at least the syntaxe seems ok and if the NPC is taking a decision to begin with, it means it works fine.
I even added debug message in order to know when the NPC is actually taking a decision.
Next guess was that it was my alarm that is supposed to reset the right of takig a decision. Here's it's just a bool and I didn't make any typo or syntaxe error.
So right now I am pretty flabergasted. Why does my NPC takes only one decision and then never again??

Here's the step event of the NPC:

if(InTalk==false)&&(NewDecision==true)
then
{
NextAction=irandom_range(0,10);
switch(NextAction)
{
case 0:
hspeed=1;
NewDecision=false;
Alarm[0]=120;
show_debug_message("decided right")
break;

case 1:
hspeed=-1;
NewDecision=false;
Alarm[0]=120;
show_debug_message("decided left")
break;

default:
hspeed=0;
NewDecision=false;
Alarm[0]=120;
show_debug_message("decided stop")
break;
}
}



And in the Alarm[0] I got:

NewDecision=true;


what gives? :/

Edited by RangerX, 12 March 2012 - 01:31 AM.

  • 0

#2 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 12 March 2012 - 12:52 AM

Perhaps InTalk is getting set to true somehow or you're setting Alarm[0] somehwere else? Failing that, try changing

if(InTalk==false)&&(NewDecision==true)
then


to

if((InTalk==false)&&(NewDecision==true)) //without then and with extra partheses

Not used to the previous syntax, so there might be an error.
  • 0

#3 RangerX

RangerX

    GMC Member

  • GMC Member
  • 923 posts
  • Version:GM8.1

Posted 12 March 2012 - 12:55 AM

I didn't make any code to change "InTalk" yet. It's only preventive.

And I always write the "then". GameMaker can live without it (so nobody use it) but its still part of GML.
  • 0

#4 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 12 March 2012 - 12:57 AM

Right, I'm just grabbing at straws here, since I don't know the problem. Try my version anyways if you haven't, but I doubt that's the problem.
  • 0

#5 RangerX

RangerX

    GMC Member

  • GMC Member
  • 923 posts
  • Version:GM8.1

Posted 12 March 2012 - 01:31 AM

Ok found the problem.

I had a capital A for in "alarm".

:/
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users