I know that maptool only posts to the chat window once the whole process is done but are there any workarounds for this?
We have a loop that calls another macro each time and that macro usually takes .25 to .4 seconds to run (very complicated, math heavy). This is no big deal when the loop is only 2-3 times....but when its 8-10, you get this nasty 4-6 second lag between calling the macro and getting all the outputs.
Is there any way around this, to get the output of the macro posted to chat for each item in the loop? rather than having to wait for the loop to finish before you get ALL of them? Or is this just so baked into the maptool backend that there's no avoiding it?
Broadcasting as a a big loop is processed
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: Broadcasting as a a big loop is processed
Instead of a loop you can have a recursive call executing the macro with a defer. This will make each iteration it's own thread and will display the output after each iteration. If you need help doing that you can share your code and I can take a look at it.
I also have another post with a progress bar here: viewtopic.php?f=3&t=28571&p=275436&hili ... ar#p275436
I also have another post with a progress bar here: viewtopic.php?f=3&t=28571&p=275436&hili ... ar#p275436
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Broadcasting as a a big loop is processed
So the loop itself looks like...
and the part where I want the text outputted to the chat window is everything inside the "Attack_Beta" macro call.
I'm not familiar with "defer" call, so any tips on that would be appreciated.
Code: Select all
[h, foreach(attack, totalAttacks), code : {
[h, if(isFumble) : return(0, 1)]
[h : i = i + 1]
[h, if(extraAttackString != ""), code : {
[h, if(i == 1) : broadcast(extraAttackString)]
[h, if(i == 2 && isRapidShot) : broadcast("Rapid Shot Attack")]
};
{
[h, if(i == 1 && isRapidShot) : broadcast("Rapid Shot Attack")]
}]
[h : newWeaponName = json.get(attack, "weapon name")]
[h, if(lastWeaponName != newWeaponName), code : {
[broadcast("With " + newWeaponName + "...")]
[h : lastWeaponName = newWeaponName]
}]
<!--Have new mods been set from switching targets?-->
[h, if(!json.isEmpty(newMods)), code : {
[h : attack = json.set(attack,
"TargetId", json.get(newMods, "TargetId"),
"StateBonus", json.get(newMods, "StateBonus"),
"TargetData", json.get(newMods, "TargetData"))]
}]
[MACRO("Attack_Beta@Lib:PC_CombatMacros"):attack]
[h : attackReturn = macro.return]
[h : isFumble = json.get(attackReturn, "isFumble")]
[h : targetWasUpNowDyingOrDead = json.get(attackReturn, "targetWasUpNowDyingOrDead")]
[h : targetDead = json.get(attackReturn, "targetDead")]
[h : targetTookPhysicalDmg = json.get(attackReturn, "targetTookPhysicalDmg")]
[h : criticalHitTarget = json.get(attackReturn, "criticalHitTarget")]
[h, if(!isFumble && i <= checkForSwitch), code : {
[h : targetId = json.get(attack, "TargetId")]
[h : alreadyAttacked = json.get(attack,"alreadyAttacked")]
[h : alreadyAdded = listContains(alreadyAttacked, targetId)]
[h, if(!alreadyAdded) : alreadyAttacked = listAppend(alreadyAttacked, targetId)]
[h, if(!alreadyAdded) : attack = json.set(attack,"alreadyAttacked", alreadyAttacked)]
[h : attack = json.set(attack,
"attackNext", json.get(attack, "attackNextId"),
"targetWasUpNowDyingOrDead", targetWasUpNowDyingOrDead,
"targetDead", targetDead,
"targetTookPhysicalDmg", targetTookPhysicalDmg,
"criticalHitTarget", criticalHitTarget
)]
[MACRO("SwitchTargetCheck@Lib:PC_CombatMacros"):attack]
[h : newMods = macro.return]
}]
}]
I'm not familiar with "defer" call, so any tips on that would be appreciated.
Re: Broadcasting as a a big loop is processed
See, I would think that this would broadcast the count as it parsed through the loop, since defer is set to 0.
But, instead, it waits until the whole loop has gone through before broadcasting 1 to 1000 in the chat window.
Code: Select all
[h : count = 0]
[h, while(count < 1000, ""), code : {
[h : count = count + 1]
[h : execFunction("broadcast", json.append("[]", count), 0, "all")]
}]
Re: Broadcasting as a a big loop is processed
AM, I read your other link a little more carefully, and I think I got it...
Call this...
Which then calls this...
And what I get in the chat window is the Count, followed by the number of milliseconds between each one...and they pop up into the chat screen approximately 1 second apart, instead of just all at once! Which is exactly what I was looking for! Now I just need to figure out how to work this into that loop that I have instead but this is definately on the right track.
One thing...I did get an empty "Owner:" in the chat screen, after each "Count = XXXX"...any idea of where in my two macros I can eliminate that?
But
Call this...
Code: Select all
[h : count = json.get(macro.args, "count")]
[h : maxCount = json.get(macro.args, "maxCount")]
[MACRO("TestLoop2@Lib:PC_CombatMacros"):count]
[h, if(count < maxCount), code : {
[h : macroLink = macroLinkText("TestLoop@Lib:PC_CombatMacros", "all", json.set("", "count", count+1, "maxCount", maxCount))]
[h : execLink(macroLink, 1, "all")]
}]
Code: Select all
[h : count = macro.args]
[h : timeTest = getInfo("server")]
[h : startMs = json.get(timeTest, "timeInMs")]
[h : duration = 0]
[h : breakLoop = 0]
[h, while(breakLoop == 0, ""), code : {
[h : end = getInfo("server")]
[h : endMs = json.get(end, "timeInMs")]
[h : duration = endMs - startMs]
[h, if(duration > 1000), code : {
[broadcast(count + " = " + duration)]
[h : breakLoop = 1]
}]
}]
One thing...I did get an empty "Owner:" in the chat screen, after each "Count = XXXX"...any idea of where in my two macros I can eliminate that?
But
Re: Broadcasting as a a big loop is processed
If you put "all" for output, then it will put out blanks. I would put none since you're doing a broadcast.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Broadcasting as a a big loop is processed
Duh!!! Thanks for pointing that out, now its doing what I want.
Tried this on something simple first, setting token Opacity (so that it fades in/out depending on what I passed in) and that worked great. Will see how to integrate this into my more complicated macro, now that I understand the gist of it.
Again, appreciate the info!
Tried this on something simple first, setting token Opacity (so that it fades in/out depending on what I passed in) and that worked great. Will see how to integrate this into my more complicated macro, now that I understand the gist of it.
Again, appreciate the info!