Stop Rep Exec Events

Started by steptoe, Wed 07/03/2012 08:27:50

Previous topic - Next topic

steptoe

Hi

I am dry running a project.

I am working on a control pad and need a little help with the following:

The Control Pad is a GUI.

On the GUI is a ListBox which has various items (weapons)

On selecting a List Item the cursor changes to ActiveInventory of that weapon.

This seems to works ok.

I Also have Flashlight Plugin On/Off Buttons. This also works.

My main problem at the moment is collide.

I have set up a boolean to be true when ListItem Sonar is selected.

When the Boolean is true (Sonar selected), I have a collide code that runs:

Code: ags

function room_RepExec()
{
 
if (Sonar==true && cEgo.x - cWaeks.x <= 30 && (cEgo.x >= cWaeks.x) || (cWaeks.x - cEgo.x < 30 && cWaeks.x > cEgo.x)
  )
  cEgo.Say("He is around here somewhere!");
  }



Obviously this will run forever in Rep Exec. (Have used in Room 1 to test)

I have tried DoOnceOnly to no avail but I obviously need to STOP Events running and allow player to carry on walking but to Run when collide and sonar are true.

What would be the best way to do this? I would prefer not to lose Sonar selected if possible as NPC character can randomly move.

EDIT
At this moment I am trying:
Code: ags

  cEgo.Say("He is around here somewhere!");
  cWaeks.Walk(cWaeks.x + 50, cWaeks.y - 0, eNoBlock, eWalkableAreas);

This Walk(cWaeks) with be Random when coded.

This seems to do what I want. I'm trying now to select ListBox Item as Inventory and use it on cWaeks.

I hope I have put this in an understandable way.

cheers


Khris

That code is a MESS.

First of all, the proper way to check whether the x distance between two character is 30 or less:
Code: ags
  int dx = cEgo.x - cWaeks.x;
  if (dx >= -30 && dx <= 30) ... 


Your long way works in theory, but the two parts not involving 30 are not needed and the brackets are all over the place, just not where they belong.

The next step is to ask yourself at which point exactly the message is supposed to appear. And Game.DoOnceOnly isn't a failsafe for putting things in RepExec that don't belong.

The sonar being the active inventory item is either true or false, and both for extended periods of time. So that condition can only be one part of the event that triggers the message.
The same thing is true for the distance condition.
As you have noticed, checking only these two results in the blocking message being displayed continuously every frame.

For a blocking message, the trigger must be an event, not a situation.
One example would be using the sonar on yourself. Another possible event would be the NPC moving inside the 30 pixels zone or back out of it, with messages like "According to the sonar, he's close now." and "The sonar doesn't indicate him being close any longer."

I'm also pretty sure you don't need the Sonar variable. Shouldn't it be enough to do if (player.ActiveInventory == iSonar)?

steptoe

Hi Khris,

thanks for your detailed response.

This is all done in the dark... via flashlight plugin.

Sonar is more a condition rather than an Inventory.

When the Sonar is selected from the ListBox it becomes 'true' and if the player gets within 30 from the NPC a display lets you know the NPC is somewhere near and the NPC moves elsewhere a little, say 10 pxls.

If you then select say Gun from the ListBox then Sonar becomes false and Gun becomes active Inventory.

Now the collide rules change. Within 30 with an active inventory will kill the NPC else outside 30 will Display ' You shoot but miss!' sort of thing.

Other Inventory includes: Knife, choker etc etc

** The collide code I used was from a while back. Yours is more compact and I will certainly give it a bash.

cheers



Dualnames

The best way to check for distances is to create an Abs function, you may make it global, but if you put it on the top of the room script it will work as well. Plus you should check for the y coordinate. I mean if the player and the cWaeks have the same x but their y property has a difference of 120, they're not even remotely close, but your previous code would think so.

Code: ags


function Abs(int value) 
{
  int val=value;
  if (val<0)
  {
    val=(val*(-1));
  }
  return val;
}


function room_RepExec()
{
  if (Sonar && Abs(cEgo.x - cWaeks.x)<=30 &&  Abs(cEgo.y - cWaeks.y)<=30)
  {//if sonar is on and cwaeks is within 30 pixels
     
  }
}

//if you want to do your last thingie

function room_RepExec()
{

 int distx=Abs(cEgo.x - cWaeks.x);
 int disty=Abs(cEgo.y - cWaeks.y);

  if (Sonar && player.ActiveInventory==iGun)
  {//if sonar is on and cwaeks is within 30 pixels and player has gun
     if (distx<=30 &&  disty<=30) 
     { 
        //kill the npc
     }
     else 
     {  
        //you miss
     }
  }
}





Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Khris

No need to use an additional variable:

Code: ags
int Abs(int value) 
{
  if (value < 0) return -value;
  return value;
}


A parameter is simply a local variable starting out with the value submitted to the function.

steptoe

Thank you so much guys.

Guess that will keep me busy for a while  ;)

steptoe



SMF spam blocked by CleanTalk