Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Setattr strange behaviour when called from scriptcard

I am using a homebrew sheet for a french game called Shaan. I have a Combat tab in which I have a repeating section called armement (weaponry). My script search the row "PistoletMitrailleur1" in this repeating section and gets various attributes to manipulate them in the script (abonus, acharg, achargmax). My script aims at simulating a firearms shot. The player is being asked the RoF (Cadence) and according to his choice different sounds are played. What I am trying to do is to decrease the amount of bullets fired (Cadence) from the current Ammo (Mun). I have a procedure called DeduireMun that calls upon setattr to set up the relevant attribut in the repeating section but weirdly enough, it does not operate ! If I output it to the chat and replace the '_' within the call by '--' and include a '!' in front, it actually does the job !! So there seems to be an issue with scriptcard calling Setattr but I can not figure out wot it is ! Any help would be greatly appreciated ! here's the full script : !scriptcard  {{   --#title|Pistolet-Mitrailleur1   --#leftsub|Armes humaines   --#sourceToken|@{selected|token_id}   --#targetToken|@{target|token_id}   -->GetAndCheckMun|   --Rfind|[*S:character_id];Pistolet-Mitrailleur1;repeating_armement;aname      --=Atk|?{Score|0} [SCORE] + [*S:ArmesHumainesPJ_Bonus] [SPE] + [$ABonus] [ACQUIS] + [$CBonus] [CdT] + ?{Bonus-Malus|0} [BONUS]     --=Dbl|@{Target|DefCorpsTotalPJ}*2    --=Tpl|@{Target|DefCorpsTotalPJ}*3   --#emoteText|[*S:character_name] attaque [*T:character_name]   --Rfind|[*T:character_id];Bouclier;repeating_protection;ptype   --=Def|[*T:corps] [CORPS] + [*T:totaldef_corps] [DEFENSE]+ [*R:pcorps] [COUVERT]    --+Résultat|[Att] : [$Atk] vs [$Def] : [Def]   --#rightsub|munitions : [$MunL] / [$Charg]      --?[$Atk] -gt [$Tpl]|BM   --?[$Atk] -gt [$Dbl] -and [$Atk] -le [$Tpl.Total]|BG   --?[$Atk] -gt [$Def] -and [$Atk] -le [$Dbl]|BL   --?[$Atk] -ge 0 -and [$Atk] -le [$Def]|Echec   --?[$Atk] -lt 0|Fumble     --:BM|   -->ApplyDamageAlterbars|@{target|token_id};3;-6   --+Blessure|[*T:character_name] subit une Blessure mortelle    --^Final|      --:BG|   -->ApplyDamageAlterbars|@{target|token_id};3;-4   --+Blessure|[*T:character_name] subit une Blessure grave    --^Final|      --:BL|   -->ApplyDamageAlterbars|@{target|token_id};3;-2   --+Blessure|[*T:character_name] subit une Blessure légère    --^Final|      --:Echec|    --+Echec|L'attaque échoue.   --^Final|   --:Fumble|   --+Fumble|L'arme s'enraye et ne peux plus être utilisée du combat!   --^Final|   --:PlayEffects|Parameters are : source effect; target effect; line effect; sound effect   --vtoken|@{selected|token_id} [%1%]   --vtoken|@{target|token_id} [%2%]   --vbetweentokens|@{selected|token_id} @{target|token_id} [%3%]   --@roll20AM|_audio,play,nomenu|[%4%]   --<|   --:ApplyDamageAlterbars|   --@alter|_target|[%1%] _bar|[%2%] _amount|[%3%]   --<|      --:GetAndCheckMun|   --Rfind|@{selected|character_id};Pistolet-Mitrailleur1;repeating_armement;aname   --=ABonus|[*R:abonus]   --=Charg|[*R:achargmax]   --=Mun|[*R:acharg]   --=Cadence|?{Cadence de tir?|1, 1|Rafale courte, 3|Chargeur, [$Mun]}   --C[$Cadence]|1:>CoupParCoup|3:>RafaleCourte|[$Mun]:>Barrage   --?[$Mun] -eq 0|NoMunLeft|DeduireMun   --<|   --:NoMunLeft|   --+|[*S:character_name] n'a plus de munitions.   --X|   --:DeduireMun|   --Rfind|@{selected|character_id};Pistolet-Mitrailleur1;repeating_armement;aname   --=MunL|[$Mun] - [$Cadence]   --setattr|_charid [*S:character_id] _[*R>acharg]|[$MunL] _silent   --<|      --:CoupParCoup|   --=CBonus|0   -->PlayEffects|none;bubbling-blood;splatter-blood;Flingue   --<|   --:RafaleCourte|   --=CBonus|1   -->PlayEffects|none;bubbling-blood;splatter-blood;PM   --<|   --:Barrage|   --=CBonus|3   -->PlayEffects|none;bubbling-blood;splatter-blood;Automatiquerafale   --<|      --:Final| }}
1615303636
David M.
Pro
API Scripter
For everyone's reference, can you share what the debug output is for your setattr command? (The line that "works" when tested from a standalone macro?)
the script's result beneath : Even if displays 17 / 21 (ammo remaining / ammo max), in fact on the sheet the value is still at 18 (the bullet shot hasn't been taken into account) So I copied and paste the 1st line & replaced '_' by '--' and got rid of the --silent option so you can see the result beneath : which in turn gives the following result : Any idea why it works when launched manually and not when fired from scriptcard !?
1615312482
David M.
Pro
API Scripter
Any setattr gurus out there that might know what is going on? I wonder if it is a translation issue? I'm not sure how translation works in Roll20, but could it be something to do with referencing "repeating_armement" when calling setattr from the API vs when a player calls it directly from a macro? Is there a French version of the character sheet, or is the translation being done in real-time somewhere in between that might be bypassed when doing it through the api?  I wonder if (for troubleshooting purposes) you hardcoded the scriptcard setattr call with "repeating_ attack ..etc" if it would suddenly work? Grasping at straws, here.
Hi everybody, Found the problem.... It actually was quite simple : I had no @ before the setattr command so the whole line was not executed at all ! Thx David by the way 'cause I spotted it following your troubleshooting suggestion (repeating_attack instead of repating_armement that didnt change a thing) SO we can close that stream !
1615612331
David M.
Pro
API Scripter
omg. facepalm. I can't believe we didn't see that earlier. Glad you figured it out!