FoundryVTT Macros 101
Vložit
- čas přidán 2. 09. 2020
- I had planned like five macros for this video, and after the first realized it was already 30 min long. So the Macro videos will be split into a couple parts.
All the code that I go over in them will be found here: github.com/spacemandev-git/fv...
Please let me know in the comments what you'd like to see me cover next!
Can't thank you enough for this video! I have a limited programming background (started with Basic in 1983!), But no prior experience with JavaScript and your video bridged some major gaps in finding the data objects I needed. Looking forward to watching the series!
Excellent! Exactly what I needed to get started with macros. Learning about the game object was pure gold. Thanks!
Very helpful. Excellent teaching as well as great foundry tips. This content is crucial for amateur developers like myself. Learned a lot about JS and FVTT. Thanks
Even with a few stuff being out of date, I was still able to learn from the video. Good content.
Thank you so much for this clear and excellent run-through of creating a macro. I've learnt so much and it's really helped me understand macro writing for foundry. Onwards to 102.
Great seeing the examples in simple world building. Thanks for your tutorials.
been struggling with getting to grips with macros in Foundry coming from using Roll20 Chat Macros regularly. This video gave me enough to get my first macro in Foundry up and running! Very helpful and really struggled to find anything else so informative
This was just what I needed. It helped me so much. Please consider making some more videos 💕👍
ooooh I struggled to get through that. I couldn't have done it without you. This is relatively new to me, the difference between the template you were using, and the dnd5e template was significant for somebody without the proper background in syntax. But I got through it. Great video! Still works March 30th 2021
Nice work here. Thanks for the tutorial. It was helpful to see you use of the console for debugging.
Nicee info man. I'm trying to learn to make modules and even system in Foundry. Glad I've found this!
I enjoy Foundry and this video has been so helpful, thankyou.
Great content! Thank you for making these!
Great video! Very well and clearly explained!
Thanks for this video! I was having trouble figuring out where to start to explore the data model, the bit starting at 2:28 helped a lot to find the right objects :)
Thank you very much for your effort and great work!
Dude is legendary. I've been avoiding writing macros (and have been having AI write them for me) because I have no experience with coding. Thank you for explaining how to read and use them. I definitely feel like I have a good idea of what I'm looking at now when I'm reading macros.
how do you do it with ai? chat GPT failed to give me anything that works.
excellent video thank you...not coded in 15+ years and coming from VB5 i was really struggling with some of the strange syntax in java.
Excellent video... thank you so much for taking the time to educate us on macros for Foundry VTT. I do have a wish list item though. I would like to understand how to increment items in a character's inventory based on a roll. For example, if a character looks for 'special stones', they would make a nature roll. if they succeed, they would roll again for a number of special stones they find. This number would then automatically increment the quantity of the item (in inventory) special stones by the number found. Ugh... hope that makes sense.
This video is getting a lot closer to what I was hoping you'd be doing! Thank you for making these and I hope you keep it up! I want to see something more akin to module development. For example, in the context of this video, how do we give Bad Actor a new attribute of Fullness because he drank too many potions?
Yup yup i wanted to work up to the more complex topics.
To answer the specific question, in simple world building that's easy because it allows for a dynamic lists of attributes for characters but in other systems it might be better done as a flag. Flags will be covered in a future video
Amazing!! I wish you could teach us a macro to update the amount of rations/water each character has by the passing of the days.
Thx!Your video helped me a lot
Amazing video, thank you sir.
Ditto on the please make more. How to set up visual studio to code for foundry vtt would be awesome too! Thanks for doing this.
This is absolutely awesome. Really informative and helpful to the foundry community. Thank you for taking the time to make this. Looking forward to more.
I'm curious how I would write a macro to roll high variance dice. For example, a d10 HV dice has these sides : 1,1,2,3,4,7,8,9,9,10.
A d20 HV dice has : 1,1,2,2,3,4,5,6,7,8,13,14,15,16,17,18,19,19,20,20
Thank you for the video!
Great tutorial!
A video on how to create a module that can install journal entries similar to the card module you used as an example would be extremely helpful.
Good video!
Amazing video...thanks a lot.
Thanks a lot this is awesome !
I’m a complete coding beginner that was really clear explanation, thanks.Could you cover how to use ‘hooks’ in a future video?
Great video, learning a lot! At 19:20 you remark "don't worry about my autocomplete". Well I do :) How do you set that up? It'll make development a lot easier.
Are you going to do more video tutorials on macros? The world needs you lol.
the best video on macros!. you are an excellent teacher too. do you plan to teach to code? it would be great!
Thank you, thank you, thank you!!
I've got a bit of experience with js, html, cs even a tiny bit of json, but NONE with the console. This is gonna help massively.
How do you get MS VS Code to auto complete like the FVTT console?? That's incredible!
This is great really helpful and insightful information, how do you include formula such as /r 2d4 + 2 in something like this is there oob function that can be called to roll the dice and get the value, then add that value to the actors health?
Need a new one of these since V10+ has changed the data model so severly.
Hi, Fantastic tutorial, I learned a lot and your style is very clear. One point confuses me though, and it's with the system rather than your tutorial but I thought you may be able to answer it. Once this line of code "let healthpotion = actor.items.find(item => item.data.name == "Health Potion");" has been executed and you have a reference to the item, why does it then need the two 'data' steps in 'healthpotion.data.data.attributes.hp_restore.value' to get to the hp_restore property? That suggests it's still only pointing at the 'actor' object to need the two 'data' steps.
Cheers
Thanks very much for the video. Could you show how to modify to heal other players or give potions to other players in a macro. There is a module but it doesn't work for the simple world-building.
wish the macro text wasn't blurry, but still good info.
For the potion macro, would nt the conditional " if (canvas.tokens.controlled.length != 1 ) would suffice for te check?
i think it should :)
Thank you for this! So, the obvious question would be: how do we wrap this macro with the actual potion? When we give the player a potion, it should come with the action to use it. I have not done it, but I feel this could be doable at least with modules like midi-qol and combat utility belt?
Hello. I have been trying to answer this question as well. Any clue on a possible solution?
What would happen if you put if(canvas.tokens.controlled.length1)
It works great on characters... but for NPCs / monsters I get an error even though it looks like it works.
Sheet value not initialized yet, please change one resource value to update it.
Dunno what that means but it does look like it works...
does this not work anymore? I cant even get past the first step when doing the drinking potion macro i get something like
Uncaught (in promise) SyntaxError: Unexpected token ')'
at Function ()
at Macro._executeScript (foundry.js:14802)
at Macro.execute (foundry.js:14765)
at MacroConfig._onExecute (foundry.js:25943)
_executeScript @ foundry.js:14802
execute @ foundry.js:14765
_onExecute @ foundry.js:25943
async function (async)
_onExecute @ foundry.js:25942
dispatch @ jquery.min.js:2
v.handle @ jquery.min.js:2
I noticed you are using Visual Studio. Which product are you using and how do you have it setup so that it will prompt the objects?
i see now that it is VS Code. Thanks I will try to get mine setup.
Problem: actor.update did not work for me. Line 43: await actor.update({"data.health.value": newHealth});
It only worked once I put a modification to th newHealth variable in there, like so:
({"data.health.value": newHealth+1});
can anybody explain why?
'Alt-Cmd i' to open developer tools on a Mac
I would like to see a similar video for module creation. Have I missed one from you?
Working up to modules wanted to cover the basics first
@@Devenish97 Enjoying your series. Lots of tidbits I didn't know about.
Is there a reason to not use tick marks (`) for all strings instead of normal quotes(" or ') even when not using the string to include a function?
Also the tutorial isn't quite systems agnostic, as attributes are a bit different from Simple World to say 5e.
No reason not to use back ticks all the time except they are a bit awkward to reach when typing code.
And as for system agnostic, I hear you, but I was hoping you can use the first methods taught in the video to look up system data for 5e and and use its attributes in the same exact way for Simple Worldbuilding
@@Devenish97 That was successful indeed! Made my potion to be a 2d4 + 2 healing potion in 5e.
@@Freeze014 i'm trying to figure out how to add the rolls. can you let me know how you did it?
Truly awesome work but I followed your code to the tee and it didn't work. VSC also doesn't let me use main() keeps trying to change it. I got fustrated after couple of hours messing with it
Great intro, but model out of data after V10 Foundry. I muddled through the new model and got it working for V11
Hello, I have made a macro to damage and heal any token. In “game master” mode everything is working fine. But players get this notification: “User {PC name} lacks permission to update Tokens in parent.” Do you know of a way to override permissions without giving GM control to players?
You need to check "Execute Macro As GM" otherwise it won't let a player change anything besides their own character sheet.
Is there a reason you need to create and call the function within the macro box? What's the difference if you just write the code without the function wrapper?
without calling the function you're just defining a function, not executing it.
Sure - but it seems I can just write “naked code” and it executed as expected with no function wrapper. In other words, it appears like the macro is already wrapped in a function, and creating the inner function (and calling it) is redundant. But I must be missing something, right?
@@chrissteele7472 yes you can do that, but that's bad code principles for anything more than simple 2-15 lines macros. like if you're writing anything even medium length it's better to break it down into functions to for better debugging and modularity. writing monolithic "naked" code becomes really hard to maintain
but yes, if you're only writing some small 2-15 line quick macro, writing naked code is fine
@@Devenish97 Thanks, I think that's what I was looking for. I certainly understand the advantages of breaking code up (I've been a developer for 35 years), but adding in a random IIFE or main() function for no reason seems, well, unnecessary. I also asked because few (if any) of the community macros (github.com/foundry-vtt-community/macros/tree/master/5e) appear to do this either. I wasn't sure if there was some reason foundry preferred it. I suspect there is more of a history here.
oh, and @spacemandev - this is an excellent video - thank you for putting this and the others out there. I'm new to foundry and your videos are the first I've come across that actually give me the level of detail I'm looking for. Great work!
I tried the following roll /r 1d20 + @health.value and received a message in the game "@health.value was not present in the provided data". I had the token selected. Not sure why it isn't working.
Hi there!
i'm following this tutorial as well and i think it is because foundry has been updated ever since and it now has an added layer of structure.
Try this instead while having a token selected
/r 1d20 + @attributes.hp.value
If you use the console (F12 and use the console tab) to do what he recommended at the very start and simply explore what it looks like in terms of structure, you can then alter these values whenever there is a change. it is very possible that a lot of people were a bit angry seeing how their macros got destroyed when the update happened!
I know this video is ancient, but I have to say, you absolutely threw me for a loop at 26:19, casually tossing that out that [[ actor.items.find(item => item.data.name == "Health Potion") ]]
There is so much javascript nonsense going on there I had to dig through multiple pages of documentation to find out that its array searching works off of running extra functions within functions, which aren't written like functions. And which return values different from what the functions themselves return. All that instead of, I don't know, just doing string comparisons like I've seen in basically every other language I've worked with.
How would I creat a Master-Macro for a Hex crael like in "The Dark of Hot Spring Island" with location selection that roles on a table to see if it is a beast / intelligent / or elemental then roels on a table for the exact monster and the motivation for the greater typ
Sorry to ruin the 999 upvotes with an additional one :/
What flavour cotton candy do you smear into your hair?
Great video! But...couldn't you simplify the new health code to this?
let newHealth = min(actor.data.data.health.value + healthpotion.data.data.attributes.hp_restore.value, actor.data.data.health.max)
I cant get " /r 1d20 + @health.value " to work
the console says "Assertion failed: Input argument is not an HTMLInputElement"
I think your macro is set to script. Try changing it to chat
You have to re-interpret as somethings have changed, and it changes even more if you are using a different system. I'm testing in Dnd 5e, on version 9, and I have to type "/r 1d20 + @attributes.hp.value"