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

[Help] First Time Coding- AOE object with SpawnFx

1587784679

Edited 1588153823
Hello, 1st post and 1st time coding, if I did not format this post or the code properly please excuse me.&nbsp; And please advise! I wanted to try and make an API that spawns out token objects that my players can use for AOE.&nbsp; All of the other APIs that I have see or tired are either broken or to difficult to setup or use. When used; the new object will spawn one square below. I have never written code before so I am unsure what I am doing.&nbsp; I am stuck on&nbsp; ReferenceError: spawnFX is not defined and I know the Line type works that was the code I started with before adding the switch(AOEType) for each one.&nbsp; I seems to breaks on the other 3 (CONE, CIRCLE, SQUARE) Please advise //commands //!AOE [TYPE] [unit Height] [Unit Width] //TYPE are either LINE, CIRCLE, CONE, SQUARE //UNITS is number of feet, default is 5 feet on("ready",function(){ sendChat("AOE API","/w GM ONLINE", null, {noarchive:true}) on("chat:message",function(msg){ if(msg.type=="api" &amp;&amp; msg.content.indexOf("!AOE")==0) { var args = msg.content.split(" "); //looks for augment after !AOE for type height and width var AOEType = args[1] if(args[1]===undefined) { sendChat("AOE API","Type, Height or Width was not entered"); return; } //Height - Feet to pixel conversion var HeightFeet = Number(args[2])*.2 if(args[2]===undefined) { HeightFeet=5*.2; } var ht=70*HeightFeet if(isNaN(ht)){ sendChat("AOE API","Please enter a vaild number for Height"); return; } //Width - Feet to pixel conversion var WidthFeet = Number(args[3])*.2 if(args[3]===undefined) { WidthFeet=5*.2; } var wt=70*WidthFeet if(isNaN(wt)){ sendChat("AOE API","Please enter a vaild number for Width"); return; } //Making sure a character was selected var selected = msg.selected; if(selected===undefined) { sendChat("AOE API","Please Select a Token"); return; } //setting imgscr var by AOE type var AOEimg var ChatText switch(AOEType){ case "Line": AOEimg = "<a href="https://s3.amazonaws.com/files.d20.io/images/126640672/RsRo9Z1l_eLjsZ6ymnvXDw/thumb.png?158770167055" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/126640672/RsRo9Z1l_eLjsZ6ymnvXDw/thumb.png?158770167055</a>"; ChatText = "is using an AOE Template of a Line " + HeightFeet/.2 +"ft. long by " + WidthFeet/.2 + "ft. wide"; break; case "Circle": AOEimg = "<a href="https://s3.amazonaws.com/files.d20.io/images/126640666/njSD_xUkdGPirWLvOiUhTg/thumb.png?15877016695" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/126640666/njSD_xUkdGPirWLvOiUhTg/thumb.png?15877016695</a>"; ChatText = "is using an AOE Template of a Circle or Sphere with at Diameter of "+ WidthFeet/.2 + "ft. wide"; break; case "Cone": AOEimg = "<a href="https://s3.amazonaws.com/files.d20.io/images/126640680/WbEAoDFGjh_T6fIDOA9C2w/thumb.png?15877016735" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/126640680/WbEAoDFGjh_T6fIDOA9C2w/thumb.png?15877016735</a>"; ChatText = "is using an AOE Template of a Cone "+ WidthFeet/.2 + "ft. long"; break; case "Square": AOEimg = "<a href="https://s3.amazonaws.com/files.d20.io/images/126640653/xEykgzycg3KXenncO2NfOw/thumb.png?15877016675" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/126640653/xEykgzycg3KXenncO2NfOw/thumb.png?15877016675</a>"; ChatText = "is using an AOE Template of a " + HeightFeet/.2 + "ft. Square or Cube"; break; default: sendChat("AOE API","Please select Square, Line, Circle, or Cone for AOE Type"); return; } var tok = getObj("graphic",selected[0]._id); var character = getObj("character",tok.get("represents")); var playerList = character.get("controlledby"); //current math sets location under selected var objLeft = tok.get("left"); var objTop = tok.get("top")+((ht/2)-(70/2))+70; createObj("graphic",{ left:objLeft, top:objTop, height:ht, width:wt, pageid:tok.get("pageid"), layer:"objects", imgsrc:AOEimg, name:tok.get("name") + "'s " + AOEType, controlledby:playerList }); sendChat(tok.get("name"),ChatText); switch(AOEType){ case "Line": spawnFxBetweenPoints({x:tok.get("left"), y:tok.get("top")},{x:tok.get("left"), y:tok.get("top")+ht}, "beam-holy", tok.get("pageid")); break; case "Circle": spawnFx(objLeft, objTop,"burst-death",tok.get("pageid")); break; case "Cone": spawnFxBetweenPoints({x:tok.get("left"), y:tok.get("top")},{x:tok.get("left"), y:tok.get("top")+ht}, "breath-fire", tok.get("pageid")); break; case "Square": spawnFx(objLeft, objTop,"bomb-water",tok.get("pageid")); break; default: sendChat("AOE API","Please select Square, Line, Circle, or Cone for AOE Type"); return; } } }); });
1587786319
GiGs
Pro
Sheet Author
API Scripter
I see a typo - it's not spawnFX , it's spawnFx.
1587786449

Edited 1587786609
GiGs said: I see a typo - it's not spawnFX , it's spawnFx. Thanks will update and see&nbsp; Yes that was the ERROR Thanks! Working now
1587786753
GiGs
Pro
Sheet Author
API Scripter
Great! I do that so often with some functions, its funny.
1588147040

Edited 1588147061
GiGs said: Great! I do that so often with some functions, its funny. 1st time coding now i know to look for those case-sensitive items. Do you know how I can change this code to work on my NPC spell casters....If I run it on a NPC it crashes the sandbox
Tye said: GiGs said: I see a typo - it's not spawnFX , it's spawnFx. Thanks will update and see&nbsp; Yes that was the ERROR Thanks! Working now fixed code above to reflect this update
1588182944
GiGs
Pro
Sheet Author
API Scripter
The source of the error isnt obvious to me. It might depend on how your npc tokens are are set up. Do your npcs have a represents set? Try changing this &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var character = getObj("character",tok.get("represents")); var playerList = character.get("controlledby"); to&nbsp; var character = tok.get("represents") ? getObj("character", tok.get("represents")) : ''; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var playerList = character ? character.get("controlledby") : '';