Ask> or dialog in an onevent subroutine

Hints, tips and tricks for newbies

Moderators: JRL, Dorian (MJT support)

Post Reply
Trautmann
Newbie
Posts: 9
Joined: Fri Jun 12, 2009 6:35 pm

Ask> or dialog in an onevent subroutine

Post by Trautmann » Fri Jul 03, 2009 7:05 pm

Hi,

Having a problem with both the Ask command and dialog boxes.

Trying to write a macro that will play a game, pretty much got there but want the user to be able to see how many rounds of the game have so far been played and exit the macro if need be.

I have set an "Onevent" routine to trigger on the key and all I want it to do is pop up a box that says how many rounds I have played and ask if I want to exit.

I tried this using Ask> But this doesn't seem to be modal (Macro kept playing the game) Also using a dialog, with the same results.

Is this because I am in an onevent or bad key choice or something else? MessageModal> works but I want the option to exit the macro so I can write a log.


Dialog code is below, triggered on shift,enter. Always seems to return a 1 for PromptResult

SRT>KeyPress


Dialog>RunningTotal
Caption=Session details
Width=357
Height=211
Top=173
Left=42
Button=Stop,152,120,75,25,1
Button=Continue,32,120,75,25,2
Label=Total Games : %Totalgames%,16,40,true
EndDialog>RunningTotal


Show>Runningtotal,PromptResult

If>PromptResult=1
Gosub>WriteSessionDetails
Exit>1
Endif

END>KeyPress

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sat Jul 04, 2009 4:27 am

This portion of your script:

Code: Select all

Dialog>RunningTotal
Caption=Session details
Width=357
Height=211
Top=173
Left=42
Button=Stop,152,120,75,25,1
Button=Continue,32,120,75,25,2
Label=Total Games : %Totalgames%,16,40,true
EndDialog>RunningTotal
Is the dialog block that defines the dialog. You can only call a dialog block once in a given script. If you call it a second time there will be an error and the dialog will not be called. Typically, dialog blocks are placed at the top of a script so that they cannot possibly get called a second time.

Your Subroutine should look like:

Code: Select all

SRT>KeyPress

Show>Runningtotal,PromptResult

If>PromptResult=1
Gosub>WriteSessionDetails
Exit>1
Endif

END>KeyPress
I don't know if you copied from your original script or not but if you did there is an extra space at the end of the line:

EndDialog>RunningTotal

That extra space would also cause the dialog definition to fail.

Trautmann
Newbie
Posts: 9
Joined: Fri Jun 12, 2009 6:35 pm

Post by Trautmann » Mon Jul 06, 2009 9:38 am

Thanks for the quick reply,

managed to get the dialog to show by moving the dialog declaration but the label to show total games is always zero. Guess its initialised with the declaration?

Workaround is to use an Ask box I guess.

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jul 06, 2009 7:02 pm

... but the label to show total games is always zero. Guess its initialised with the declaration?
Yes it is initialized with the initial declaration, and it can be changed at any time by setting the variable that contains the label's value then calling either the ResetDialogAction> or the GetDialogAction> function

Code: Select all

Let>Totalgames=0

Dialog>RunningTotal
Caption=Session details
Width=357
Height=211
Top=173
Left=42
Button=Stop,152,120,75,25,1
Button=Continue,32,120,75,25,2
Label=Total Games : %Totalgames%,16,40,true
EndDialog>RunningTotal

Show>Runningtotal,PromptResult

//After you pick a button the variable "Totalgames" will be incremented up
//and the dialog will redisplay with the lable updated to show the increment.

Let>Totalgames=%Totalgames%+1
Let>RunningTotal.mslabel1=Total Games : %Totalgames%
ResetDialogAction>RunningTotal

Show>Runningtotal,PromptResult

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts