Re: GW2 bot goals & ideas
Posted: Sun Jul 29, 2012 6:21 pm
hehe...indeed 
tho, the states themselves technically arent loops...they a run, or a sequence...its just that they happen to be called repeatedly from a loop
all very droll, but it is in fact an important point of differences as it means the states are short running and only handle the stuff they should - they don't get bogged down with looping etc.
This will cause problems of course, in that sometimes you will want a state to loop / block / wait until an event occurs. But thats just a paradigm shift:
e.g.
old style
possible new style:

tho, the states themselves technically arent loops...they a run, or a sequence...its just that they happen to be called repeatedly from a loop

This will cause problems of course, in that sometimes you will want a state to loop / block / wait until an event occurs. But thats just a paradigm shift:
e.g.
old style
Code: Select all
function SellingState:update() --player is already at the merchant and needs to sell stuff
while (sellDialogNoOpen) do
player:target(merchant);
player:attack();
end;
end;
Code: Select all
include("../state.lua");
SellingState = class(State);
SELLSTATE_STARTED = 0;
SELLSTATE_OPENING_DIALOG = SELLSTATE_STARTED+1;
SELLSTATE_DIALOG_OPENED = SELLSTATE_OPENING_DIALOG+1;
SELLSTATE_COMPLETE = SELLSTATE_DIALOG_OPENED+1;
function SellingState:constructor()
self.name = "Combat state";
self.lasttime = os.time(); -- We're going to just fake combat with time.
self.dialogIsOpen = false;
self.state = SELLSTATE_STARTED;
end
function SellingState:update()
if (self.State == SELLSTATE_STARTED) then
if (merchant is close enough) then
self.State = SELL_OPENING_DIALOG;
else
stateman.pushState(moveToMerchant);
end;
elseif (self.State == SELL_OPENING_DIALOG) then
player:target(merchant);
player:attack();
if (dialogIsOpen) then
self.State = SELLSTATE_DIALOG_OPENED;
end;
elseif (self.State == SELLSTATE_DIALOG_OPENED) then
if (player:sellMyLootz()) then
self.State = SELLSTATE_COMPLETE;
stateman.popState();
end;
elseif (self.State == SELLSTATE_COMPLETE) then
stateman.popState();
end;
end