X-ing out of an input window

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

X-ing out of an input window

Post by Lee »

Hi, everyone. First and foremost, I'd like to say that MapTool is awesome. I've been getting by learning how to use through the excellent resource material found here and in the tutorials. As the title of this post suggests, I've come across behavior that I couldn't find an answer to. When I use the "X" to close out an input window, it returns a nullpointer exception instead of returning a 0 that I was hoping for. Obviously, I want to catch this exception to avoid players inadvertently flooding the chat window with programmatic errors. Here's the code snippet:

[h: status = 0]
[while(status == 0), code: {
[status = input("radioStance| Full Attack, Attack, Defense, Full Defense, Center |Stance| RADIO | orient=h", "radioFacing| North, NE, East, SE, South, SW, West, NW |Facing| RADIO | orient=h")]
}]

I'm looping this to force player input as it is a combat function. I guess I won't need help on this if there was some way to control the modal to only have the "Ok" button sans the "Cancel" and "X" controls.

Thanks!

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: X-ing out of an input window

Post by Rumble »

Couple things:

1) Program errors usually only show up in the window for the person who they affect, if I recall correctly.

2) Just put [h:abort(status)] inside the while loop, after the input call. If status is 0, which happens if they hit X or cancel, it will abort rather than throw errors. Like so:

Code: Select all

[h: status = 0]
[while(status == 0), code: {
[status = input("radioStance| Full Attack, Attack, Defense, Full Defense, Center |Stance| RADIO | orient=h", "radioFacing| North, NE, East, SE, South, SW, West, NW |Facing| RADIO | orient=h")]
[h:abort(status)]
}]

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: X-ing out of an input window

Post by wolph42 »

Rumble wrote:Couple things:

1) Program errors usually only show up in the window for the person who they affect, if I recall correctly.

2) Just put [h:abort(status)] inside the while loop, after the input call. If status is 0, which happens if they hit X or cancel, it will abort rather than throw errors. Like so:

Code: Select all

[h: status = 0]
[while(status == 0), code: {
[status = input("radioStance| Full Attack, Attack, Defense, Full Defense, Center |Stance| RADIO | orient=h", "radioFacing| North, NE, East, SE, South, SW, West, NW |Facing| RADIO | orient=h")]
[h:abort(status)]
}]
I don't think that is correct (not sure though) IIRC if you 'cancel' then result = 0 if you 'x' then result = "". I remember running into this problem. Although what I did then was abort(status=input()) and although I would expect that not to work, it did...

ah here it is (its more different):
the following:

Code: Select all

[input("x")]
results in
Cancel:
« input("x") = input("x") = 0 »
Ok:
« input("x") = input("x") = 1 »
X:
« input("x") = Invalid expression: input("x"). »
so my abort() method won't work. Yours (rumble) will because you initialize 'status' and the macro continues after the 'invalid expression' ignoring that line'
In other words: a shorter version that will also work:

Code: Select all

[status = 0]
[status = input("x")]
[h:abort(status)] 

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: X-ing out of an input window

Post by Azhrei »

Wolph, is this current for b87? I thought this was one of the things I fixed for the b87 release. If it's still broken this way, please confirm and I'll look at it again and figure out what went wrong. Thanks.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: X-ing out of an input window

Post by aliasmask »

confirmed. still gives an error.


Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

Re: X-ing out of an input window

Post by Lee »

Thanks Wolph and Rumble for the information and insights. Unfortunately, it still throws the exception even though I've tried both of your suggestions. Also, I don't really want to abort the loop on Cancel as it will break the chain of dependencies that follow after :) I've been programming a framework for about a month now and while the initial run was steep, it gets more rewarding everyday. I've gone through a lot of your materials and everyone's contributions are astounding I must say. Thanks for everything and I'll be glad to wait for any developments on this particular matter :)

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: X-ing out of an input window

Post by Rumble »

Lee wrote:Thanks Wolph and Rumble for the information and insights. Unfortunately, it still throws the exception even though I've tried both of your suggestions. Also, I don't really want to abort the loop on Cancel as it will break the chain of dependencies that follow after :) I've been programming a framework for about a month now and while the initial run was steep, it gets more rewarding everyday. I've gone through a lot of your materials and everyone's contributions are astounding I must say. Thanks for everything and I'll be glad to wait for any developments on this particular matter :)

Note: if you abort on a cancel, everything stops dead. It will not throw errors or break any dependencies; all macro processing is halted. Now, if you change something on a token before you do that and then abort, that change happens, but once abort is called, everything halts.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: X-ing out of an input window

Post by wolph42 »

I think what you are looking for is a minor adjustment on rumbles suggestion:

Code: Select all

[h: status = 0]
[while(status != 1), code: {
[status = input("radioStance| Full Attack, Attack, Defense, Full Defense, Center |Stance| RADIO | orient=h", "radioFacing| North, NE, East, SE, South, SW, West, NW |Facing| RADIO | orient=h")]
[h:abort(status)]
}]
This will repop the input if someone hits cancel. The only way to exit is by pressing ok.

Lee
Dragon
Posts: 958
Joined: Wed Oct 19, 2011 2:07 am

Re: X-ing out of an input window

Post by Lee »

Thanks guys, appreciate the time you took to help me with this. While these do work great in handling Cancel status, my real problem is when a user just clicks on the 'X' to close the window and not use Esc or the Cancel button. The window simply does not return anything, throwing a nullpointerexception. I'm not sure what triggers that without digging through the code for input() but even a simple [input("x")] will throw an NPE when closed through the 'X'

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: X-ing out of an input window

Post by Azhrei »

I've added this to my hitlist for b88.

Post Reply

Return to “Macros”