Jump to content


Photo
* * * - - 2 votes

Ai Command Stack


  • Please log in to reply
60 replies to this topic

#51 yodamerlin

yodamerlin

    GMC Member

  • GMC Member
  • 194 posts
  • Version:GM:Studio

Posted 25 December 2012 - 09:27 PM

I don't know if anyone will read this. However I want to have pathfinding in a topdown however I don't get how to use the pathfinding at all. I have seen the demo but it makes no sence to me, anyone, help.
  • 0

#52 yodamerlin

yodamerlin

    GMC Member

  • GMC Member
  • 194 posts
  • Version:GM:Studio

Posted 25 December 2012 - 09:28 PM

I don't know if anyone will read this. However I want to have pathfinding in a topdown however I don't get how to use the pathfinding at all. I have seen the demo but it makes no sence to me, anyone, help.
  • 0

#53 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 26 December 2012 - 07:08 AM

I don't know if anyone will read this. However I want to have pathfinding in a topdown however I don't get how to use the pathfinding at all. I have seen the demo but it makes no sence to me, anyone, help.


If it's too intense, I find it too intense reading it now, you probably would benefit from make your own similar but less complete system
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#54 hans80

hans80

    GMC Member

  • GMC Member
  • 26 posts

Posted 04 September 2013 - 04:25 PM

links are down :(

plz reup 8.1 version, thx

 

edit: works again :)


Edited by hans80, 05 September 2013 - 09:05 AM.

  • 0

#55 TheMagician

TheMagician

    GMC Member

  • GMC Member
  • 632 posts

Posted 24 April 2014 - 11:15 PM

Thank your for your great work, icuurd!

Just as you've susgested in THIS TOPIC I use it to create a command list system for an adventure game engine.

I've just converted my favourite AGS function into GML: Wait(steps)  :thumbsup:

 

A hint for people who want to use this in GameMaker: Studio. There will be a long list of error messages when you first try to start the demo.

However, this is very simple to fix. Just find the following scripts:

  • CommandStackSequenceAdd
  • CommandListAdd
  • CommandStackPush

In each of them replace any occurence of argument0 with argument[0]. Everything works great then.


  • 1

#56 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 25 April 2014 - 02:45 AM

Thanks!


  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#57 graefchen

graefchen

    GMC Member

  • New Member
  • 16 posts
  • Version:GM:Studio

Posted 13 September 2015 - 01:18 PM

Hello,

 

I had a look at the scripts and saw that you use flags to figure out on what call of the command we are: "//return 0 when not done, 1 when done, -1 when done and hurge to proceed with the next event right away". Now, I dont understand -1, in CommandsPerform() it seems like this would just call CommandsPerform again, kind of like a while loop. Is that true?

 

 

This is the part in CommandsPerform, the last line:

data = ds_stack_top(m_cmdstkdata);
var res;
res = script_execute(ds_stack_top(m_cmdstkscripts), data)
data.action = 3;
if (res = 0) return 1;
CommandStackPop();
if(res = -1) return CommandsPerform();

Also, in all your example scripts, you dont always use this flag system. Instead of having everything that should be performed in the 3 flag code block, it is just below it. Is this so it gets performed on the first call (flag 2) and all subsequent calls (flag 3)?


  • 0

#58 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 13 September 2015 - 09:49 PM

You command script is called to allocate your required data, then to run the code (first time and subsequent) and the final flag to free your data once you told the system you were done.


Many examples do the exact same thing on "first run" and "subsequent run" so the code is outside, below, the case 2 and 3, since I dont exit in the if
//return 0 when not done, 1 when done, -1 when done and urge to proceed with the next event right away

//A data objects is provided to store your information for the command
var data;
data = argument0;

//A flag tells you if you are initializing, 
//starting the action, 
//continuing the action 
//or done with the command
if(data.action = 0) //pushed (added to stack)
{
    //init vars/create stuff

    data.MoveSpeed = data.arg1;
    data.TurnSpeed = data.arg2;
    data.Enemy = data.arg3;
    data.MaxDist = data.arg4;
    return 1;
}
else if(data.action = 1) //poped (removed from stack)
{
    //done... free stuff
    return 1;// done
}
else if(data.action = 2) //first actual "perform the action" call
{
    //start performing
}
else if(data.action = 3) //subsequent call
{
    //keep performing
}

//show_debug_message("         Attacking: " + string(data.Enemy));
if!(instance_exists(data.Enemy)) return -1;
var dtr;
/*
draw_set_color(c_red);
draw_line(-view_xview[0]+x,-view_yview[0]+y,-view_xview[0]+data.Enemy.x,-view_yview[0]+data.Enemy.y);
screen_refresh();
*/
dtr = degtorad(point_direction(x,y,data.Enemy.x,data.Enemy.y)-image_angle);
image_angle += sin(dtr) * data.TurnSpeed;
direction = image_angle;
speed = cos(dtr) * data.MoveSpeed;
if(point_distance(x,y,data.Enemy.x,data.Enemy.y)>data.MaxDist) return -1;
return 0;// not done
A) so each step.
if it's the first time the scrip is set to run:
YourScript() with data.action 0 is called, then right away
YourScript() with data.action 2, first run

B) then each step
YourScript() with data.action 3 is called for as long as you return 0

When you return 1
YourScript() with data.action 1 is called, to free your data
The next script will be set to be called on the next step, return to A) on the next step

When you return -1
YourScript() with data.action 1 is called, to free your data
The next script is called right away, return to A) now.

When should you return -1 instead 1? if your instance movement for example makes a noticeable 1 step stop, basically that is the main reason

Edited by icuurd12b42, 13 September 2015 - 09:49 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#59 graefchen

graefchen

    GMC Member

  • New Member
  • 16 posts
  • Version:GM:Studio

Posted 14 September 2015 - 05:50 AM

Okay, this makes everything clearer, thank you very much.


  • 0

#60 graefchen

graefchen

    GMC Member

  • New Member
  • 16 posts
  • Version:GM:Studio

Posted 14 September 2015 - 11:28 AM

I am experimenting with this system, and I have come across something: There doesnt seem to be an option to push a new command and deleting the old one from the stack. For example, take the provided PatrolToXYscript: When you are near an enemy, you will start to attack it (the AttackEnemy command gets pushed on the script). Then the PatrolToXY script returns 0, meaning it is not finished and will stay on the stack, below the AttackEnemy command. I thought if you would change the return value from 0 (not finished) to 1 (finished), that would mean the Patrol script would get pushed off the stack, and the the AttackScript added. But actually, the AttackScript gets pushed, then the PatrolScript returns 1 and the stack gets popped, meaning the Attack script is immediately removed. Is there a way to realise this? I want to end a command and remove it from the stack, then the new command should be pushed.


  • 0

#61 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 14 September 2015 - 08:41 PM

You can probably call
CommandStackPop()
before
CommandsStackPush()

just be sure to not use the "data." after the pop

CommandStackPop()
The system will call the script (you are in) to tell it to free the data it allocated
It will pop the script from the stack, deleting it,
meanwhile you are still in that script, so return 0 do it does not pop it (since it's popped)

....
var MyData1 = data.variable1;
var MyData2 = data.variable2;
var MyData3 = data.variable3;
CommandStackPop();
//---Your script is recalled with option 2 to free your allocated data. you are now in a recursive state
//---data container is freed so no longer valid
//---this script is removed from the stack, but still executing
//back in the script now
CommandStackPush(YourOtherScript, MyData1,MyData2,MyData3)
return 0;// so the system does not perform the pop

of couse a better way is simply to have a ImDone variable to the data

add data.ImDone = false on action 1


on action 2 and 3

//you were done before, quit to prev script
if(data.ImDone) return -1;
//when you are done but put want to pop stuff
if(ContidionThatSaisImDone())
{
//make it so that when returning from this push I just pop
data.ImDone = true;
CommandStackPush(YourOtherScript, data.variable1,data.variable2,data.variable3);
}
return 0; //not done... done will be handled later, gradually popping the scripts


that was the system will take care of it's own

Edited by icuurd12b42, 14 September 2015 - 08:53 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button