Jump to content


Photo
- - - - -

Ai Command Stack


  • Please log in to reply
52 replies to this topic

#41 Sir

Sir

    Jedi Poodoo

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

Posted 18 December 2011 - 08:17 PM

Desktop Death Match is a good example, see main post


Here is a very complicated setup

http://www.host-a.net/u/icuurd12b42/station16.gmk


arrows move, shift and z to shoot, t to tractor on and off

Move to the bottom, tag a cylinder with your tractor beam. then use the tractor beam to move and attach another cylinder to the first one, tractor and push it and release before it hits the cylinder, both should snap together. add modules (on top of the cylinders) to your station, a power source, a radar (it will tag you as friendly if you avoided the already built station at the top), a asteroid beam, a processing platform.... Once tagged by your station, the other ships should attack you if too close. Meanwhile they gather resources.

The AI ships are controlled with the command stack. The player ship also is. that way you could take control of another ship byt simply adding the pleyer control script to the ai ship stack.


Ok, im looking at the shipobj, and this is in the beggining of the step event

if(CommandsPerform() = 0) 
{
    CommandStackPush(MainScript);
}

VelocityStep();
RotationStep();

So, if i understand correctly, You initialize the com stack in the create event, Then in the step event for the AI, you make
if(CommandsPerform() = 0) 
{
    CommandStackPush(MainScript);
}
Then you list the scripts you want exocuted, in the line you want them done in?

Edited by SirGuy, 18 December 2011 - 08:20 PM.

  • 0

#42 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 18 December 2011 - 09:15 PM

MainScript is a variable than can hold either cmdPlayerControlor cmdPatrolForRocksRandom. as an initiator. Look at cmdPatrolForRocksRandom (or whatever I named it) this is the start of the AI brain.


Basically, if it's the player controlling the ship, that code in the step just calls cmdPlayerControl every step, but in a round about way. (I was planing to allow player control on all ships, that is why it's like that)


However, for AIs it's cmdPatrolForRocksRandom, the command list and stacks will grow and shrink and grow and shrink until everything is resolved.... Then it starts all over again.

I think I forget to add the state to attack enemy... you can push cmdPatrolToXY self.x,self.y in the AIship in an alarm that check every second. Or just set the Mainscript to patrol random if you want to see a fight.

I was planing for the station to issue orders to ships, play with each of their commands list and stack remotely to issue attack orders. And to have wing leader (the player) issue command to wing squad. So the basic behavior was to gather resources until someone told them to attach (push the attack script in the stack)

You can loose you mind pretty fast if you dont document your behavior.
  • 0

#43 Sir

Sir

    Jedi Poodoo

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

Posted 18 December 2011 - 09:49 PM

I am loosing my mind. I have no idea what i am missing, but i am missing something. I am still not understanding what this is doing! Like, i see no clear indacation in the code where you are doing

:start
(1)Go to 5,43
(2)mine
(3)Return
(4)Dump what you mined
(5)goto start

EDIT:

Wait a second. I thought you had the scripts all seperate, so the master script would call one, when that one was over it would call the next, and so on. But the way you have it, One script calls the next, yes?

Edited by SirGuy, 18 December 2011 - 10:29 PM.

  • 0

#44 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 18 December 2011 - 11:47 PM

The main command script, the foundation of the AI mind is usually in charge of deciding what to push in the stack.


on create, you create a command stack space

on step, you call the command stack to perform it's <current> action, if the return says it's done, you reset/re-add the default behavior. It can be a single script, a main command script, or you could add a few things to do, like say define a set of patrol points to go to... I prefer to have the main script do that.

on destroy, you destroy the command stack


That is really only 3 things you object need doing

create
CommandsCreate();

step
//Perform the AI task list
if(CommandsPerform() = 0) 
{
    CommandListAdd(AIMainScript, whatever, arguments, that, script, needs);
or
    CommandStackPush(AIMainScript, whatever, arguments, that, script, needs);
}
The difference between list and stack, list items are done one after the other, stack items are performed last in first out. But this is discussed in the main post

on destroy
CommandsFree();

oh, room end event
on room end
if(!persitent and !room_persitent) CommandsFree();

That is the core of the system.

AIMainScript is the core of your system. If you simply put all your AI code in there, without using the system anymore, not pushing more of your smart scripts, then might as well not use the command stack at all.

That said, say you want to make a capture the flag AI, I wont talk about the script pre-processing, or about the fact you can make the script execute and pop out early, just the logic.

AIMainScript
CommandStackPush (MoveToFlag, thespeed);
MoveToFlag
if(global.FlagHolder != id and instance_exists(global.FlagHolder)) CommandStackPush (FindFlagHolder, thespeed), exit;
MoveTowardsWhileFighting( flag.x, flag.y, thespeed)
FindFlagHolder
MoveTowardsWhileFighting( FlagHolder.x, FlagHolder.y, thespeed)
MoveFlagToBase
MoveTowardsWhileFighting (base.x, base.y, thespeed)
On AI Collision With flag
with(flag) instance_destoy();
global.FlagHolder = id;
CommandStackPush (MoveFlagToBase, thespeed);
On AI destroy
if(global.FlagHolder == id) instance_create(x,y,flag)
CommandsClear();

  • 0

#45 Sir

Sir

    Jedi Poodoo

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

Posted 19 December 2011 - 11:23 PM

Where is the command stack supposed to stop? I figured out how to use it, but it keeps giving this error when the AI hits the waypoint that i made...

ERROR in
action number 1
of Step Event
for object obj_military:

Trying to execute non-existing script.

Why? It doesnt give this error when the AI goes for an enemy before going for the waypoint, so why isnt it working?
  • 0

#46 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 19 December 2011 - 11:54 PM

is it possible you have a script name that has the same name as a sprite or an object
  • 0

#47 Sir

Sir

    Jedi Poodoo

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

Posted 20 December 2011 - 12:38 AM

No, all our sprites are named spr_something, and all our obj's are named obj_something. What gives? I can pm you the gmk if you want to take a closer look at it.
  • 0

#48 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 20 December 2011 - 07:55 PM

No, all our sprites are named spr_something, and all our obj's are named obj_something. What gives? I can pm you the gmk if you want to take a closer look at it.


quite simply

change
CommandListAdd(AIMilitary());

to
CommandListAdd(AIMilitary);

See you need to pass the script id, you were calling CommandListAdd passing AIMilitary()... GM executed AIMilitary() right there and CommandListAdd added the return result of AIMilitary()
  • 0

#49 Sir

Sir

    Jedi Poodoo

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

Posted 20 December 2011 - 10:10 PM

Worked like a charm. Thank you.
  • 0

#50 4 KINGS

4 KINGS

    BioThirst Studio

  • New Member
  • 549 posts
  • Version:GM8

Posted 27 January 2012 - 05:57 AM

sabotage?

P.S. I was talking about the spam above me that is now gone.
P.S.S. I'm not insane...... ...... it really was there!

Edited by 4 KINGS, 27 January 2012 - 08:01 AM.

  • 1

#51 yodamerlin

yodamerlin

    GMC Member

  • GMC Member
  • 92 posts
  • Version:GM8

Posted 25 December 2012 - 09:13 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
  • 92 posts
  • Version:GM8

Posted 25 December 2012 - 09:14 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

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 26 December 2012 - 06:54 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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users