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

Createobj To Back

Is there something I can put in the Createobj function to have a token show up in the background?  IE If I make a Spirit Guardians token to show the user has these, it would be nice if I didn't have to immediate To Back it because it was automatic.  Group Linked the to player who called the API would be even more fantastic so it would move with him.
1752505661
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Johnny Meat shield! In that very particular case, you could have it spawn to the map layer, and have the script triggered by the movement of the summoning character to move the map level token the same amount. As for the general question, I'm not sure. I haven't worked too much with that kind of code.
I could be wrong but I don't think createObj on a token would have a parameter in it to do the z-order directly in the same call. My reason for thinking that is the z-order isn't an attribute of a Graphic object. It's actually a parameter of the Page object . But I could easily be wrong as the bulk of my API interactions are through ScriptCards abstractions rather than direct interaction via JS Mods. That said, depending upon the specific ask, I have done ScriptCard work that is similar to what is being described, ScriptCard to spawn a token, move it to the back, and then have a ScriptCard trigger mirror token movement with a change:graphic  trigger so if it's possible via ScriptCards it should be possible directly in a custom Mod.
Thanks guys, I guess I'll stick to manual.  I just took a look at that scriptcards wiki and man it's huge.  I tinker with Power Cards as they do look nice but don't think I have the mental energy to get into scriptcards right now.
ScriptCards does have a lot of options. It's super flexible. Here is a link to some  tutorials that  can hopefully help out if and when you want to learn ScriptCards. They are designed to get you building some examples and show off different features of the language as introductions with links to the relevant Wiki for further reading if and when you need.
Thanks!
Joshua N. said: I could be wrong but I don't think createObj on a token would have a parameter in it to do the z-order directly in the same call. My reason for thinking that is the z-order isn't an attribute of a Graphic object. It's actually a parameter of the Page object . But I could easily be wrong as the bulk of my API interactions are through ScriptCards abstractions rather than direct interaction via JS Mods. That said, depending upon the specific ask, I have done ScriptCard work that is similar to what is being described, ScriptCard to spawn a token, move it to the back, and then have a ScriptCard trigger mirror token movement with a change:graphic  trigger so if it's possible via ScriptCards it should be possible directly in a custom Mod. Joshua N., A bit cheeky to ask but have you got a sample script card for this ?. The spawn part will be great and the mirror movement could be a game changer for my group.
1752602582

Edited 1752623232
EDIT: Kurt announced that 3.0.12 is going to be the 1-Click version soon. <a href="https://app.roll20.net/forum/post/11175456/script-scriptcards-thread-number-2/?pageforid=12433032#post-12433032" rel="nofollow">https://app.roll20.net/forum/post/11175456/script-scriptcards-thread-number-2/?pageforid=12433032#post-12433032</a> &nbsp;So hopefully soon the part following part about fetching from Github won't be necessary. Sure FFR. I actually redid the Spawn ScriptCards to take advantage of some new features that Kurt added to the latest ScriptCards. So that one does require a newer version of ScriptCards than what is in the 1-Click install. Which you can grab the latest version&nbsp; here from Github . The 3.0.12 version has support for reading the _defaulttoken property of a Character which simplifies my old setup. 1.&nbsp; ScriptCards Triggers &nbsp;requires a character to be created named ScriptCards_Triggers and that character needs to have an ability named change:graphic Note: I don't think that can be a Beacon sheet at the moment. I'm not sure because I stopped testing on Beacon sheets so I could be wrong here. 2. After creating that character, restart the API Mod Sandbox so ScriptCards registers that character for triggers. You'll see a message like: 3. In the change:graphic &nbsp;ability on ScriptCards_Triggers this is the ScriptCard: !script {{ --&amp;LogLevel|error --&amp;EnableLinkedTokenMirroring|true --&amp;LinkageLocation|gmnotes --&amp;LinkagePrefix|linked --/|TRIGGER_REPLACEMENTS --#hidecard|1 --/|Check if linked token mirroring is enabled --?"[&amp;EnableLinkedTokenMirroring]" -ne "true"|[ --&gt;LogMessage|DEBUG;Linked token mirroring is not enabled. exiting --^Done| --]| --/|Check if the change was a token moving --?"[&amp;GraphicNewlastmove]" -eq "[&amp;GraphicOldlastmove]"|[ --&gt;LogMessage|DEBUG;old lastmove [&amp;GraphicOldlastmove] same as new lastmove [&amp;GraphicNewlastmove] so change was not movement. exiting --^Done| --]| --/|Check if the changed token is linked --?"[&amp;GraphicNew[&amp;LinkageLocation]]" -ninc "[&amp;LinkagePrefix]"|[ --&gt;LogMessage|DEBUG;Linkage location [&amp;LinkageLocation] on changed token [&amp;GraphicNew[&amp;LinkageLocation]] does not contain linkage prefix of [&amp;LinkagePrefix]. exiting --^Done| --]| --&gt;MoveLinkedToken|[&amp;GraphicNew_id] --:Done| --X| --:MoveLinkedToken|SourceTokenID --&gt;LogMessage|DEBUG;Inside MoveLinkedToken function with source token of [%1%] --&amp;_mltLinkedToken|[*[%1%]:t-[&amp;LinkageLocation]] --&amp;_mltLinkedToken|[&amp;_mltLinkedToken([&amp;LinkagePrefix(length)])] --&gt;LogMessage|DEBUG;Linked token id [&amp;_mltLinkedToken] would get moved to match top [*[%1%]:t-top] and left [*[%1%]:t-left] --!t:[&amp;_mltLinkedToken]|top:[*[%1%]:t-top]|left:[*[%1%]:t-left] --&gt;LogMessage|DEBUG;Leaving MoveLinkedToken function --&lt;| --:LogMessage|MessageLevel;Message --&amp;_lmPrefix|SC change:graphic trigger --&amp;_lmMessageLevel|[%1%] --?"[&amp;_lmMessageLevel(tolowercase)]" -eq "fatal"|_lmSENDTOCONSOLE --&amp;_lmNum|1 --?"[&amp;LogLevel(tolowercase)]" -eq "warn"|&amp;_lmNum;10 --?"[&amp;LogLevel(tolowercase)]" -eq "info"|&amp;_lmNum;100 --?"[&amp;LogLevel(tolowercase)]" -eq "debug"|&amp;_lmNum;1000 --&amp;_lmMLNum|1 --?"[&amp;_lmMessageLevel(tolowercase)]" -eq "warn"|&amp;_lmMLNum;10 --?"[&amp;_lmMessageLevel(tolowercase)]" -eq "info"|&amp;_lmMLNum;100 --?"[&amp;_lmMessageLevel(tolowercase)]" -eq "debug"|&amp;_lmMLNum;1000 --?[&amp;_lmMLNum] -gt [&amp;_lmNum]|_ENDLOG --:_lmSENDTOCONSOLE| --\log|[&amp;_lmPrefix] [&amp;_lmMessageLevel(touppercase)]: [%2%] --?"[&amp;_lmMessageLevel(tolowercase)]" -eq "fatal"|Done --:_ENDLOG| --&lt;| }} 4. This is the ScriptCard to spawn a default token and link it to the selected token: !script {{ --/|CONFIGURATION VARIABLES --&amp;CharacterToSpawn|SpellArea-Square --&amp;LinkageLocation|gmnotes --&amp;LinkagePrefix|linked --&amp;SquareSize|4 --&amp;PixelSize|70 --&amp;SC_Minimum_Version|300120 --#title|Spawn and Link Tokens --#sourceToken|@{selected|token_id} --?[&amp;SC_VERSION_NUMERIC] -lt [&amp;SC_Minimum_Version]|[ --+ERROR|Must have at least ScriptCards 3.0.12 installed to work with _defaulttoken properties. Exiting --^Done| --]| --&gt;lookupCharacterIDbyName|[&amp;CharacterToSpawn];SpawnCharID --?"[&amp;SpawnCharID]" -eq "NotFound"|[ --+ERROR|Could not find character id for [&amp;CharacterToSpawn]. Make sure only 1 character starting with [&amp;CharacterToSpawn] exists. Exiting --^Done| --]| --~|hash;set;OverrideProps;top==[*S:t-top];left==[*S:t-left];_pageid==[*S:t-_pageid];height==[= [&amp;SquareSize] * [&amp;PixelSize] ];width==[= [&amp;SquareSize] * [&amp;PixelSize] ] --&gt;SpawnDefaultToken|[&amp;SpawnCharID];OverrideProps;NewTID --&gt;MoveTokenToBack|[&amp;NewTID] --&gt;LinkTokens|[*S:t-id];[&amp;NewTID] --+Spawned|Token [&amp;NewTID] spawned and linked to [*S:t-name] --:Done| --X| --:SpawnDefaultToken|CharacterToSpawn;TokenPropertyOverrideHash;StringReturnVariable --~|array;fromkeys;_sdtOverKeys;[%2%] --~|hash;fromjson;_sdtDTHash;[*[%1%]:_defaulttoken] --~|array;fromkeys;_sdtDTKeys;_sdtDTHash --~|array;define;_sdtTokenPropArray --%_sdtDTProp|foreach;_sdtDTKeys --~_sdtOverIdx|array;indexof;_sdtOverKeys;[&amp;_sdtDTProp] --?"[&amp;_sdtOverIdx]" -ne "ArrayError"|% --~|array;add;_sdtTokenPropArray;[&amp;_sdtDTProp]:"[:_sdtDTHash("[&amp;_sdtDTProp]")]" --%| --%_sdtOverProp|foreach;_sdtOverKeys --~|array;add;_sdtTokenPropArray;[&amp;_sdtOverProp]:"[:[%2%]("[&amp;_sdtOverProp]")]" --%| --~_sdtTokenPropList|array;stringify;_sdtTokenPropArray;| --!ot:[%3%]|[&amp;_sdtTokenPropList] --&lt;| --:LinkTokens|SourceTokenID;SpawnedTokenID --!t:[%1%]|[&amp;LinkageLocation]:[&amp;LinkagePrefix][%2%] --&lt;| --:MoveTokenToBack|TokenID --z:graphic:[%1%]|toback --&lt;| --:lookupCharacterIDbyName|CharacterName;StringReturnVariable --~|array;objects:character;_lcibnCharArr;[%1%] --?"[@_lcibnCharArr(length)]" -eq 0|&amp;[%2%];NotFound --?"[@_lcibnCharArr(length)]" -ge 2|&amp;[%2%];NotFound --?"[&amp;[%2%]]" -eq "NotFound"|&lt; --&amp;[%2%]|[@_lcibnCharArr(0)] --&lt;| }} So there are some configuration at the top that you may need to adjust: --&amp;CharacterToSpawn|SpellArea-Square --&amp;LinkageLocation|gmnotes --&amp;LinkagePrefix|linked --&amp;SquareSize|4 --&amp;PixelSize|70 The &amp;CharacterToSpawn is the name of the Character that has the default token you want to summon. So in my case I have a character named SpellArea-Square that has a defaulttoken set to the token i want to use an area. &amp;LinkageLocation is the location on the selected token that will get the linked token id. In this case the gmnotes field but could be bar3_max or tooltip or wherever you prefer. &amp;LinkagePrefix is what the LinkageLocation will start with. So in the example above, the selected token's gmnotes field would get "linked-sometokenid" &amp;SquareSize is how big of a square to summon. This could get changed to separate heights and width as needed but for simplicity sake this example is a square. &amp;PixelSize is 70 which is the default pixel size for a page in roll20 and is used to determine size of height and width of summoned token in conjuction with &amp;SquareSize. So the Spawn ScriptCard will spawn a token at the same location as the selected token, move the spawned token to the back, and add the spawned token id to the selected token's gmnotes field. Then when a token is changed, the change:graphic &nbsp;will check if linked movement is enabled, if the change was movement, and if the changed token has that linkage prefix. And if it does, it will move the linked token to the same location the source token moved to. Note that this is not real time. The linked token moves after the source token is dropped. So there is a little lag. I wish it were real time but I don't think that's possible with Roll20 event triggers today. I'd love to be wrong on that though. Let me know if you have any questions about that.
Joshua, Thanks so much for sharing. I think I understand what you've provided and will test over the weekend. One question though. what would I need to change to not link the spawned token eg a fireball token
Essentially it would be this line: --&gt;LinkTokens|[*S:t-id];[&amp;NewTID] If you want to remove the linkage option entirely, remove that line and this section: --:LinkTokens|SourceTokenID;SpawnedTokenID --!t:[%1%]|[&amp;LinkageLocation]:[&amp;LinkagePrefix][%2%] --&lt;| If you wanted to give the option to link, you could wrap that in a conditional like so: --?"[&amp;EnableLinkage]" -eq "true"|&gt;LinkTokens|[*S:t-id];[&amp;NewTID] and you could have the variable `--&amp;EnableLinkage|true` or false in your Scriptcard. Or you could prompt for that with either a roll query or a re-entry button in the Scriptcard. Or if you have a way to test another way like if the spell duration property is Instantenous or something then make that the condition.