#### Archived

This topic is now archived and is closed to further replies.

# Execution cycle clarification

This topic is 5608 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

From the readme file: "As you send commands to the GDArena, only the first time a command is sent will it be executed. This means that if you send a TurnLeft() command early on in your processing, and then later send a TurnRight() command, only the TurnLeft() command will be processed by the arena during that Update() cycle." So what happens to the TurnRight() command? Is it processed during the next update cycle, or is it simply thrown away? More generally, what happens to the non-first commands during each Update()? Are they queued and executed during later update cycles? Or is only the first command from Update() called, and then the rest discarded?

##### Share on other sites
I beleive they are simply discarded, but don''t hold me to that. I only call anything once per update using states, if something needs modifications, I change the variable, then at the bottom of the update, based on the few variables, it does the movements, turning, and strafing... this way, it could only ever get called once, and it doesn''t matter how the system works internally .

##### Share on other sites
It means if you do...

{  TurnRight(TURN_SLOW);  // ... more code here ...  TurnLeft(TURN_SLOW);

Then only the TurnRight(TURN_SLOW); line will be executed. All other commands dealing with turns will be thrown away. Now, if you do:

{  TurnRight(TURN_SLOW);  SetSpeed(SET_NORMAL_SPEED);  // ... more code here ...  TurnLeft(TURN_SLOW);}

Your bot will turn right at the slow rate and move forward at the normal speed. The TurnLeft() is tossed out.

If you do:
{  SetSpeed(SET_NORMAL_SPEED);  Strafe(STRAFE_LEFT);    // ... more code here ...  TurnRight(TURN_FAST);  SetSpeed(SET_HIGH_SPEED);}

Your bot will walk forward at the normal rate and strafe to the left while also turning at a fast rate to the right. The SET_HIGH_SPEED is tossed out.

Basically, Turn*() and SetSpeed() are independent of each other, but you can only set one rate per update (the first one you set). Strafe() is independent of both of those.

Weapon selection and firing works the same way. The first time you call SelectWeapon() during an update is the only time it will actually execute. All calls to SelectWeapon() after that will be ignored by the arena. Same with Fire() and SetWeaponAngle(). This way, you can''t do this in one Update() cycle:

{   // fire 50 grenades and 50 bullets in this Update() cycle   for (int idx = 0; idx < 100; idx++)   {       if (idx % 2)           g_pCore->SelectWeapon(WEAPON_GUN);       else           g_pCore->SelectWeapon(WEAPON_GRENADE);       g_pCore->Fire();   }}

...or some other variation. Essentially, this gives you one shot per frame, particularly when you take into account recoil and reload times.

I hope that explains things..

##### Share on other sites
Ok, this is how I currently understand things. Basically only the first call of any of these will actually get run from Update():

bool TurnLeft(int rate); or bool TurnRight(int rate);bool SetSpeed(int speed);bool Strafe(int strafe);bool SelectWeapon(int weaponType);void SetWeaponAngle(float angle);bool Fire();int GetNumObjectsInSight();bool GetObjectsInSight(int objIdx, int &objectType, float &direction, float &distance);bool Taunt(const char *tauntStr);int GetMyHealth();int GetMyAmmoCount();int GetMyGrenadeCount();

Also, I assume only the first call to Taunt() or GetMy*() also only get run once, which would make it good practice to only Taunt() once per Update(), as well as save all of the health/ammo/grendate/objects-in-sight-info/etc. at the beginning of Update() and work with that instead of making multiple calls to those functions if that data is needed in multiple spots in Update(). Tell me if I understand correctly now

##### Share on other sites
I assume with GetMy* functions that you could call them as many times as you want. It''s only hurting you (execution time) to do so anyway.

##### Share on other sites
quote:
Original post by Russell
Ok, this is how I currently understand things. Basically only the first call of any of these will actually get run from Update():

bool TurnLeft(int rate); or bool TurnRight(int rate);bool SetSpeed(int speed);bool Strafe(int strafe);bool SelectWeapon(int weaponType);void SetWeaponAngle(float angle);bool Fire();int GetNumObjectsInSight();bool GetObjectsInSight(int objIdx, int &objectType, float &direction, float &distance);bool Taunt(const char *tauntStr);int GetMyHealth();int GetMyAmmoCount();int GetMyGrenadeCount();

Also, I assume only the first call to Taunt() or GetMy*() also only get run once, which would make it good practice to only Taunt() once per Update(), as well as save all of the health/ammo/grendate/objects-in-sight-info/etc. at the beginning of Update() and work with that instead of making multiple calls to those functions if that data is needed in multiple spots in Update(). Tell me if I understand correctly now

Nope.. unless I''m misunderstanding you..

You should just run some experiments. You will see that you can''t turn multiple times, you can''t set the speed multiple times, and you can''t strafe in opposite directions. You also can''t fire your weapon more than once, and you can only select your weapon one time. You can do all that stuff together, but you can only do each thing once. As for taunts, if you are in debug mode, you can set it as often as you''d like, but that would be pretty difficult to read. If you are in release mode, the taunt will last 1.5 seconds before it will update again. All the Get*()''s can be executed as often as you want. You just can''t try to move multiple times, turn multiple times, select and fire your weapon multiple times, or do any other thing multiple times that might affect the realtime nature of the arena.

##### Share on other sites
mind another question re: Update SelectWeapon() and Fire() operability?

if a bot already has a selected weapon (gun) and calls Fire() followed by a SelectWeapon(grenade), will the Fire() be dumped due to the weapon change or will it trigger a use of the gun first followed by the weapon change?

no problem if you don''t know as i''ll be testing this soon anyway.

##### Share on other sites
quote:
Original post by Anonymous Poster
mind another question re: Update SelectWeapon() and Fire() operability?

if a bot already has a selected weapon (gun) and calls Fire() followed by a SelectWeapon(grenade), will the Fire() be dumped due to the weapon change or will it trigger a use of the gun first followed by the weapon change?

no problem if you don''t know as i''ll be testing this soon anyway.

At the end of the Update(), your selected weapon will be gun, and you will have fired one shot. The second SelectWeapon() will be ignored.

##### Share on other sites
quote:
Original post by Khawk
At the end of the Update(), your selected weapon will be gun, and you will have fired one shot. The second SelectWeapon() will be ignored.

just to clarify, there weren''t two SelectWeapon calls during one Update cycle. the gun had already been selected via a previous Update cycle. so during the current Update cycle the sequence was simply Fire followed by a SelectWeapon(grenade). but i''ve tested things and found the answers so thanks anyway.

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633759
• Total Posts
3013719
×