• To improve security, we will soon start forcing password resets for any account that uses a weak password on the next login. If you have a weak password or a defunct email, please update it now to prevent future disruption.

HTML Sugarcube capture inside replace inside timed

Sewyoba

Member
Jul 22, 2018
331
254
I'm using the latest Sugarcube and have run into some dumb problem. Code looks something like this:

Code:
<<timed 40ms>>
...
<<for _i = 0; _i < $battle.allies.length; _i++>>\
              ...
              <<replace _temp>>\
                         ...
                        <<capture _i>><<link "[?]">>
                              <<set $battle.chardescr = $battle.allies[_i]>>
                              <<script>>
                               Dialog.setup("Character Detail");
                               Dialog.wiki('<<display "BattleCharacterDetail">>');
                               Dialog.open();
                               <</script>>
                        <</link>><</capture>>
                        ...
               <</replace>>
               ...
<</for>>
...
<</timed>>
So, it causes a error - dialog opens, but $battle.chardescr happens to be completely at the mercy of random - on link [?] press it either works as intended first couple of times, becomes undefined or _i == 0 and thus it shows description for only the first ally in array. I don't change array inside the loop, it doesn't change in 40ms period, so i assume it's replace macro that's at fault? Similar code for a different functionality reloads the page and always works as intended, but it maybe due to bug having not enough rolls to kick in.
 

Alcahest

Engaged Member
Donor
Game Developer
Jul 28, 2017
3,157
4,053
Hard to say when you don't show all the code, but have you made sure it's not about the page not being fully rendered yet, which is required when using replace? 40ms might not be enough time to load the page.
 

Sewyoba

Member
Jul 22, 2018
331
254
Hard to say when you don't show all the code, but have you made sure it's not about the page not being fully rendered yet, which is required when using replace? 40ms might not be enough time to load the page.
No, page's rendered - I replace span after 40 ms with some other text, run some code and add a link inside that replaced span. It all should be rendered. Checked with higher ms values, no difference.

Problem was pretty stupid, actually - inside that dialog i've been running a for cycle with standard _i (the same one kept local by capture) as iterator. Thanks for the idea, anyway, it helped
 
  • Like
Reactions: Alcahest

Alcahest

Engaged Member
Donor
Game Developer
Jul 28, 2017
3,157
4,053
Problem was pretty stupid, actually - inside that dialog i've been running a for cycle with standard _i (the same one kept local by capture) as iterator. Thanks for the idea, anyway, it helped
Yeah, that kind of error was the first thing that came to mind since I've had similar errors, like when forgetting that variables aren't localized in widgets.