Page 1 of 2

How can CheckEvent() Fail?

Posted: Tue Aug 31, 2010 12:09 am
by Bugala
This is dummiest thing so fdar.

I have just created buttons, and then i do:

1: a=1
2: Repeat
3: CheckEvent()
4: Until a=0


And it keeps compolaining to me that: "3: Wrong Usage/parameters for this command! Read the documnetation"

Re: How can CheckEvent() Fail?

Posted: Tue Aug 31, 2010 12:29 am
by Bugala
and it doesnt help even i take every other line away and replace it with:

WaitEvent()


It sill still complain the same about WaitEvent() as it complains of CheckEvent()

Re: How can CheckEvent() Fail?

Posted: Tue Aug 31, 2010 9:55 am
by jalih
Hello,

I think you need to gives us more info on this one. Post some button creation and callback code.

Re: How can CheckEvent() Fail?

Posted: Tue Aug 31, 2010 12:15 pm
by Bugala
Competition time is now over and i didint get my product finished thanks to this bug.

It pretty much buggers me since i believe i have had very good shot to even win some of the categories had i got it completeable.

But it would still be nice to know why did it bug, so here some more code:

Code: Select all

Function p_QuestionButton2(msg)

  Switch msg.action

   Case "OnMouseOver":
      SetLayerStyle("qtext2"..msg.id, {color=$cccccc})
   Case "OnMouseOut":
      SetLayerStyle("qtext2"..msg.id, {color=$777777})
   Case "OnMouseDown":
      endloop2=0
      Local temp=at.temporaryconversation.current
      If at.wisdoms[msg.id] = at.temporaryconversation[temp].questions[3].usewisdom
         at.tempconv.current = at.temporaryconversation[temp].questions[3].rightanswer
      Else
         at.tempconv.current = at.temporaryconversation[temp].questions[3].wronganswer
      EndIf
      For n = 1 To at.wisdoms.currentamount
        RemoveLayer("qtext"..n)
        DeleteButton(n)
      Next
      RemoveLayer("textdisplaybox")
      nextfreelayer=nextfreelayer-1
      P_Conversation()
  EndSwitch

EndFunction






Function p_QuestionButtonWisdom(msg)

  Switch msg.action

   Case "OnMouseOver":
      SetLayerStyle("qtext"..msg.id, {color=$cccccc})
   Case "OnMouseOut":
      SetLayerStyle("qtext"..msg.id, {color=$777777})
   Case "OnMouseDown":
      endloop=0
      /*at.temporaryconversation.current=at.temporaryconversation[tempnum].questions[msg.id].answer.jumpto */
      For n = 1 To answeroptions
        RemoveLayer("qtext"..n)
        DeleteButton(n)
        nextfreelayer=nextfreelayer-1
      Next
      RemoveLayer("textdisplaybox")
      nextfreelayer=nextfreelayer-1

      /*here on the wisdom specific stuff*/


      CreateBrush(1, 1700, 70*at.wisdoms.currentamount, $333333)
      InsertLayer(nextfreelayer, #BRUSH, 1, #CENTER, #CENTER)
      SetLayerName(nextfreelayer, "textdisplaybox")
      SetLayerTransparency("textdisplaybox", 32)
      nextfreelayer=Add(nextfreelayer, 1)

      SetFont(#SANS, 50)
      SetFontColor($777777)

      endloop2=0
      temptop=600-((70*at.wisdoms.currentamount)/2)
      temp=0
      For n=1 To at.wisdoms.currentamount
         MakeButton(temp, #SIMPLEBUTTON, 70, temptop-50+(70*n), 1700, 70, questionbutton2)
         TextOut(70, temptop-50+(70*n), at.wisdoms[n].name, {name="q2text"..n})
         temp=temp+1
      Next

      While IsLeftMouse() = True
      Wend
      While endloop2=0
         WaitEvent()                    < <  < ============ CRASH!!!! <<<<=======
      Wend

      For n=1 To at.wisdoms.currentamount
        RemoveLayer("q2text"..n)
        DeleteButton(n)
      Next
      RemoveLayer("textdisplaybox")
      nextfreelayer=nextfreelayer-1

      P_Conversation()
  EndSwitch

EndFunction

i put both the crashing place as well as questions2 button, since maybe it has soemthing to do with this all, as it is questions2 buttons event table that is being used on newly created buttons.

To my understanding those buttons really are created. For i tried putting waitmouselft() before waitevent() and at least the box and text are displayed there. And if that textout is executed, then should the makebutton too since they are both at same place, right next to each other.

Re: How can CheckEvent() Fail?

Posted: Tue Aug 31, 2010 1:44 pm
by jalih
I think the reason simply is that you are calling WaitEvent() or CheckEvent() inside a buttons callback function. Try to move it to some other place.

Re: How can CheckEvent() Fail?

Posted: Tue Aug 31, 2010 3:39 pm
by Bugala
Hmm, that would make sense. Although i am bit disappointed at same time if it is so.

For basically I am deleting the button inside which the waitevent happens before making those new buttons.

So basically the buttons part and waitdevent and so on, could be kind of deleted too before they are done.

But its stupid if it is so. Since im not jumping out of those that button until the new buttons are deleted too and it anyway makes the new buttons.

Re: How can CheckEvent() Fail?

Posted: Tue Aug 31, 2010 10:15 pm
by jalih
Bugala wrote:For basically I am deleting the button inside which the waitevent happens before making those new buttons.

So basically the buttons part and waitdevent and so on, could be kind of deleted too before they are done.

But its stupid if it is so. Since im not jumping out of those that button until the new buttons are deleted too and it anyway makes the new buttons.
Why not just use one callback function for all the buttons? Small example below, which I took from Hollywood documentation and modified to better suit for your case.

Code: Select all

	Function p_MyFunc(msg)

		Switch msg.action
		Case "OnMouseUp":
			DebugPrint("User left-clicked button", msg.id)
			If msg.id = 1
				DeleteButton(1)
				Box(0, 0, 100, 100, #BLACK)
				Box(200, 200, 100, 100, #BLUE)
				MakeButton(2, #SIMPLEBUTTON, 200, 200, 100, 100, evtmatch)
				
			ElseIf msg.id = 2
				DeleteButton(2)
				Box(200, 200, 100, 100, #BLACK)
				Box(0, 0, 100, 100, #RED)
				MakeButton(1, #SIMPLEBUTTON, 0, 0, 100, 100, evtmatch)
			EndIf			
		Case "OnMouseOver":
                        DebugPrint("User moved mouse over button", msg.id)
		Case "OnRightMouseUp":
                        DebugPrint("User right-clicked button", msg.id)
		EndSwitch
	
	EndFunction


	Box(0, 0, 100, 100, #RED)
        
	evtmatch = {OnMouseUp = p_MyFunc, OnMouseOver = p_MyFunc, OnRightMouseUp = p_MyFunc}
	MakeButton(1, #SIMPLEBUTTON, 0, 0, 100, 100, evtmatch)


	Repeat
		WaitEvent
	Forever

Re: How can CheckEvent() Fail?

Posted: Wed Sep 01, 2010 2:09 am
by Bugala
Because buttons were created dynamically depending on the data, so just the msg.id wouldnt have been enough to program know what kind of button was pressed if they were all done with same button. There fore i needed two differfent buttons, since msg.id (1) could have as well been of button type 1 as well as button type 2.


But good idea otherwise, have to keep that in mind. Might be useful in some other program. And im also wondering if i would be possible to send those buttons some sort of identification info. Like could you give while you crate button, despite using the same evttable something like button.name="unique name".

That way you could do:

switch msg.action

case "OnMouseDown":

switch self.name
case "name1"
case "name2"
...



anyone know if this kind of thing is possible to do?

Re: How can CheckEvent() Fail?

Posted: Wed Sep 01, 2010 6:32 am
by jalih
Bugala wrote:And im also wondering if i would be possible to send those buttons some sort of identification info. Like could you give while you crate button, despite using the same evttable something like button.name="unique name".

That way you could do:

switch msg.action

case "OnMouseDown":

switch self.name
case "name1"
case "name2"
...

anyone know if this kind of thing is possible to do?
Just define button names as constants or variables and use them in place of id:

Code: Select all

Const #BUTTON1 = 1
Const #BUTTON2 = 2

button3 = 3
button4 = 4

Re: How can CheckEvent() Fail?

Posted: Sat Sep 04, 2010 10:56 pm
by airsoftsoftwair
What jalih says is perfectly correct. It's not allowed to use WaitEvent()/CheckEvent() in a function that has been called by WaitEvent()/CheckEvent(). It should be possible to write programs in a way that only a single call to WaitEvent() is necessary.