Problem with "While"...**SOLVED**

Started by Knox, Fri 01/10/2010 22:26:16

Previous topic - Next topic

Knox

Im trying to get a "while" function to work, but Im missing something...

I have a list (lstRadioCode) and when the selection is changed in that list, the text in the radio's screen display gets updated with the text from the list...when this text is updated, I can then press a button "push to talk" and it will send the text that is in the radio's screen display to the dispatcher.

All works well except I added a doubleClick function...if the selection in the list is doubleClicked on, it will read what text is in the radio's screen display (txtRadio_CodeInput) and call the "push to talk" function. There is a delay in updating the text from the list to text box, so I decided to put a "while" in the script cause I want to make sure the text box gets the new text from the list before executing the "push to talk".

Here is what I tried, but at the "while" part, it just keeps on waiting, never exiting the loop...but I set the bool "Ready" to true AFTER the textbox gets updated:

Code: ags

void doubleClick(eDoubleClickSpeed eSpeed)
{
  ViewFrame *frame0 = Game.GetViewFrame(VWAIT_FAKE, 0, 0);
  if (frame0.Graphic != 2061) frame0.Graphic = 2061;
  mouse.ChangeModeView(eModeWait, 54); //fake "Pointer-Wait" view...(waitMouseKey shows Wait View)
  mouse.ChangeModeGraphic(eModeWait, 2061);
  
  int iDoubleClick;
  int dc;
  if (eSpeed == eSlowClick) dc = 15;
  else if (eSpeed == eMediumClick) dc = 12;
  else if (eSpeed == eFastClick) dc = 9;
  
  iDoubleClick = (WaitMouseKey(dc) * mouse.IsButtonDown(eMouseLeft));
  if (iDoubleClick)
  {
    //Display("Double click!");
    iExecuteDC = 1;
    mouse.ChangeModeView(eModeWait, 14); //restore Default Wait view
    mouse.ChangeModeGraphic(eModeWait, 297);
  }
  else iExecuteDC = 0;
}

void lstRadioCode_OnSelectionChange(GUIControl *control)
{
  bReady = false;
  clearTXT(txtRadio_CodeInput);
  String selectedItemText = lstRadioCode.Items[lstRadioCode.SelectedIndex];
  txtRadio_CodeInput.Text = selectedItemText;
  bReady = true;
}

void on_event (EventType event, int data)
{
  overGuiControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  if (event == eEventGUIMouseDown && (overGuiControl == lstRadioCode))
  {
    doubleClick(eMediumClick);
    if (iExecuteDC == 1)
    {
      if (gRadio.Visible)
      {
        while (bReady != true) fakeWaitCursor(1, 2091);
        Display("Ready!");
        //btnRadio_Send_OnClick(btnRadio_Send, eMouseLeft);
      }
    }
  } 
}


I dont quite understand why this isnt working!
--All that is necessary for evil to triumph is for good men to do nothing.

Lufia

When a while loop is running, it's the only thing that's running. All you do in your loop is call fakeWaitCursor over and over again. You need to change the value of bReady somewhere in there to break the loop.

Knox

Ok, so if I change the value of bReady in repeatedly_execute_always, then the while loop can continue...

Does stuff in the "on_event" get processed before "lstRadioCode_OnSelectionChange"? If so, how in the crap can I get "bReady" to be true so that when I get to the on_event part, it can finally exit that while loop?

Man Im all mixed up on this one..arrrrg
--All that is necessary for evil to triumph is for good men to do nothing.

Wyz

AGS will not do parallelism when you use a while loop so ditch the loop. You can use the repeatedly_execute event to check if the state you're awaiting was already occurred; if not return form the function. The next game loop it will be fired again. It helps to draw diagrams if your in it like this. ;)
Life is like an adventure without the pixel hunts.

Knox

Nice, I got it to work! Here is what I did:
Code: ags

void lstRadioCode_OnSelectionChange(GUIControl *control)
{
  //copy the contents of that selection to the radio LCD area
  clearTXT(txtRadio_CodeInput); //first clear whats in the LCD
  String selectedItemText = lstRadioCode.Items[lstRadioCode.SelectedIndex];
  txtRadio_CodeInput.Text = selectedItemText;
  bReady = true;
  //Display("Selection changed...");
}

function repeatedly_execute() 
{
  overGuiControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  if (overGuiControl == lstRadioCode)
  {
    if (iExecuteDC == 1) //this is set from doubleClick command
    {
      if (bReady == true)
      {
        //Display("Send message");
        btnRadio_Send_OnClick(btnRadio_Send, eMouseLeft);
        iExecuteDC = false;
        bReady = false;
        return;
      }
    }
  }
}



Thanks for your help!
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk