I have a project I'm working on that involves a "onChangeSelection" and I've done something stupid in my code that's resulting in an endless loop, freezing Maptool completely.
The problem is, I can't MODIFY the macro to fix this because the moment I click on the library token, it goes into this loop and freezes!
Is there any way to stop this, so I can actually modify the macro that's causing the issue?
Caught in a loop...
Moderators: dorpond, trevor, Azhrei
Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior.
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior.
Re: Caught in a loop...
Oh onSelect. You need to have an open frame that's running the code to run that handler, so close that window.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Caught in a loop...
and next time make sure that your lib is of a certain property type and make a check to NOT run onchangeselction for that prop type.
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
Re: Caught in a loop...
I made the same mistake in my original reply, but onChangeSelection doesn't care about prop types. It just runs when a token is selected or deselected or clicked. It doesn't use the stat sheet.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Caught in a loop...
Got it fixed, thanks! I do need to add in a check for property type, good call.
That had me sweating there for a minute...
That had me sweating there for a minute...
Re: Caught in a loop...
I actually have some generic code that handles instances of selecting a token, double selecting a token, deselecting and multi-select. I went ahead and added some comments to help translate.
Code: Select all
@@ @onTokenSelect
[H: eventId = macro.args]
<!-- property saved on players personal lib token, but you can do this with the new table functions -->
[H: lastEventId = am.play.getPlayerProperty("selectEventId")]
<!-- onChangeSelect executes multiple times. This stops the duplication -->
[H: matchingEvent = if(eventId == lastEventId,1,0)]
[H, if(matchingEvent): abort(0)]
<!-- get current selection and saved selection on lib token -->
[H: selectedTokens = getSelected("json")]
[H, if(json.isEmpty(selectedTokens)): selectedTokens = "[]"]
[H, if(json.type(selectedTokens) == "UNKNOWN"): selectedTokens = json.fromList(selectedTokens)]
[H: selectedList = am.play.getPlayerProperty("selectedTokenList")]
[H, if(json.isEmpty(selectedList)): selectedList = "[]"]
<!-- difference in selection - added tokens to selection -->
[H: selectChange = json.difference(selectedTokens,selectedList)]
<!-- difference in deselection - removed tokens from selection -->
[H: deselectChange = json.difference(selectedList,selectedTokens)]
<!-- onChangeSelect executed but no change in selection means a token was reselected -->
[H: eventProcessed = json.equals(selectedTokens,selectedList)]
<!-- only one token has been selected -->
[H: singleSelect = if(json.length(selectedTokens) == 1,1,0)]
[H, if(! eventProcessed), code: {
<!-- There was a change in selected tokens -->
[H: am.play.setPlayerProperty("selectedTokenList",selectedTokens)]
[H, if(! json.isEmpty(deselectChange)), code: {
<!-- deselection event processing -->
[H: link = macroLinkText("multiDeselectChange@"+getMacroLocation(),"none",deselectChange)]
[H: execLink(link,1)]
};{}]
[H, if(! json.isEmpty(selectChange)), code: {
<!-- new selection event processing -->
[H: link = macroLinkText("multiSelectChange@"+getMacroLocation(),"none",selectChange)]
[H: execLink(link,1)]
};{}]
[H: am.play.deferFunction("am.play.openSelectFrame")]
[H: am.play.setPlayerProperty("selectEventId",eventId)]
};{
[H, if(singleSelect), code: {
<!-- double click/select event processing -->
[H: broadcast(strformat("<b>Double Click: </b>%s",getName(json.get(selectedTokens,0))))]
[H: am.play.deferFunction("am.play.openSelectFrame")]
[H: am.play.setPlayerProperty("selectEventId",eventId)]
};{}]
}]
!!
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Caught in a loop...
Good stuff, I'll have to see if I can incorporate some of this.