1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. While the majority of active discourse on D20PRO has moved to our Discord Channels, this forum is still active and checked-in on regularly by our staff. However, for the very latest information, conversation and/or immediate support, please join us on Discord here: http://discord.gg/Ph38ckM
    Dismiss Notice

Scripting troubles

Discussion in 'General Discussion' started by WorstPlayerEver, Jun 18, 2018.

  1. WorstPlayerEver

    WorstPlayerEver New Member

    Joined:
    Jun 15, 2018
    Messages:
    11
    Likes Received:
    0
    I am having troubles with some custom scripting in 3.7.3. I am trying to add my own data to the caster object, I guess this may not be supported. Normally in javascript, you can just invent new properties and assign them values on the fly in the code, the declaration is inferred from the usage. Here I am trying to account for items and effects that directly buff caster level during spellcasting or other ability usages. However, executing this script code:

    function mystuff_setCasterLevelBonus(amount){
    print('set caster level adjust = ' + amount);
    caster.mystuff_castlvladjust = amount;
    print('object val = ' + caster.mystuff_castlvladjust);
    return 0;
    }

    produces output on the game log like :

    set caster level adjust = 4
    object val = undefined

    Future attempts to access and use the caster.mystuff_castlvladjust variable result in it being undefined. Is there a way to store/retrieve custom data such as this on the game objects?
     
  2. Wesley Gorby

    Wesley Gorby Production/Community Manager
    Staff Member

    Joined:
    Aug 1, 2011
    Messages:
    2,443
    Likes Received:
    140
    as far as I know, there currently is not. But I'll poke @owlbear and ask him to look at this thread and weigh in on it.
     
  3. WorstPlayerEver

    WorstPlayerEver New Member

    Joined:
    Jun 15, 2018
    Messages:
    11
    Likes Received:
    0
    Thanks, I appreciate any advice on the matter.

    I noticed a few other things that have me scratching my head...

    I created a feature that adds a deflection bonus to armor class. However, it stacks with itself and other features that add different numerical values of the exact same bonus type (I assumed it would only use the highest bonus of a given type). In the Modify Target box I tried AC - Deflect - Deflection, AC - Deflect - Magic, AC - Armor - Enhancement, all with the same result (stacking with itself or a copy of itself providing the same bonus with a different "value" in the flow). Not sure what I am doing wrong here in specifying these things.

    Is there any way to use the output of a script function in the description text of a feature/spell? By which I mean the final node on the flow element which holds text that ultimately appears on the mini - effects tab. If a spell or feature is providing a variable bonus based on something like caster level, I was hoping to make the final computed value appear on the mini tab when inspected in game. Something like

    'Deflection bonus to AC = ' + (2 + getSpellcastingClassLevel() / 6)

    in the flow box just treats the whole thing as a text literal string.
     
  4. Wesley Gorby

    Wesley Gorby Production/Community Manager
    Staff Member

    Joined:
    Aug 1, 2011
    Messages:
    2,443
    Likes Received:
    140
    I'd really need to be able to see that, to offer advice. screenshot?
     
  5. WorstPlayerEver

    WorstPlayerEver New Member

    Joined:
    Jun 15, 2018
    Messages:
    11
    Likes Received:
    0
    I hope this is clear enough. I created two effects identical except in name, each adding a deflection bonus to armor class. In the rules of D&D 3E, (as well as 3.5 and Pathfinder), two bonuses of the same "type" (e.g. "deflection") do not stack or add together, instead they "overlap" and the highest takes precedence. You can see how the first effect is defined in the screen shot marked shieldoffaith.png. The second is a copy of it with the name changed to ShieldOfStrongBelief. You can see the target with only the first effect applied in oneeffect.png, then both effects applied in twoeffects.png. Notice how the target's armor class displays with a +6 deflection bonus in the twoeffects.png screenshot. I verified it is calculated incorrectly on the GM attack confirmation screen as well, so it is not just a context pop-up window display problem.

    You can also see the results of my failed attempt to control/affect the description text. In the flow window I attempted to use a script function to change the description text dynamically, but only the literal string value was applied, I was wondering if there was some way to use scripting to affect the value.

    shieldoffaith.png oneeffect.png twoeffects.png
     
  6. Wesley Gorby

    Wesley Gorby Production/Community Manager
    Staff Member

    Joined:
    Aug 1, 2011
    Messages:
    2,443
    Likes Received:
    140
    as far as I know, you need to get and add or subtract from the current value.

    So aside from setting the value to a static number, you would need to create a var

    nAC = target.get.ac.parameters.types.value; // don't know the exact container for this off the top of my head

    then adjust that var according to your needs.

    nAC = nAC + 2;

    and return that var to the node value

    return nAC;

    the current Effect->AC->Value node sets the target element to a Int value. (stated/declared or returned from a script)

    As to the Description node, I haven't played with that too much, not sure why that is not reporting as expected.
     
  7. WorstPlayerEver

    WorstPlayerEver New Member

    Joined:
    Jun 15, 2018
    Messages:
    11
    Likes Received:
    0
    Is there any documentation on the details of the target and caster objects? The auto-complete inside the script editor doesn't seem to have very much to go on, mainly it just displays the other library functions. Or any way to debug and see the objects and their member data as they are executing in real time?
     
  8. WorstPlayerEver

    WorstPlayerEver New Member

    Joined:
    Jun 15, 2018
    Messages:
    11
    Likes Received:
    0
    Tried a javascript trick to enumerate the object but it didn't work, I am guessing the scripting language is more guarded and less robust to prevent crashing from pesky users.

    Was just trying to do something like :

    for ( var key in target )
    {
    print(key + " -> " + target[key]);
    }

    to peek at the first order member variables (was going to try to introduce some recursion if that had worked).
     
  9. Wesley Gorby

    Wesley Gorby Production/Community Manager
    Staff Member

    Joined:
    Aug 1, 2011
    Messages:
    2,443
    Likes Received:
    140
    so what you'd write would look something like so..

    upload_2018-6-21_10-56-43.png

    upload_2018-6-21_10-57-42.png

    Deselecting/Cancelling the options you do not want.

    upload_2018-6-21_11-1-7.png

    upload_2018-6-21_11-8-38.png

    this is effectively done via

    flow-order-of-operation.png

    and the setDescription() script is as follows.

    upload_2018-6-21_11-10-40.png

    here are the files;
     

    Attached Files:

  10. WorstPlayerEver

    WorstPlayerEver New Member

    Joined:
    Jun 15, 2018
    Messages:
    11
    Likes Received:
    0
    Thank you very much, looks promising. Is there any documentation about all of the functions that exist for feature or caster or target (i.e. knowing that .getBehavior().setShortDescription() even exists is a big stumbling block for would-be novice script writers)?
     
  11. Wesley Gorby

    Wesley Gorby Production/Community Manager
    Staff Member

    Joined:
    Aug 1, 2011
    Messages:
    2,443
    Likes Received:
    140
  12. WorstPlayerEver

    WorstPlayerEver New Member

    Joined:
    Jun 15, 2018
    Messages:
    11
    Likes Received:
    0
    Awesome, thanks! I had not found the advanced script doc before.
     

Share This Page