Generating a random number for damage
Generating a random number for damage
Apologies if this has been answered before or if it should be common programming sense, but I'm wondering how to generate a random number in a dialogue lua script. I'm trying to make it so attacks do damage in a range (say, between 1 and 6 damage) and I'm wondering what command to put in for that. Thanks!
Re: Generating a random number for damage
Hi Alex,
Use the "math.random" function. Examples:
or:
Use the "math.random" function. Examples:
Code: Select all
Variable["Damage"] = math.random(1, 6)
Code: Select all
TakeDamage(math.random(1, 6))
Re: Generating a random number for damage
Thank you! I wasn't sure if that function worked in lua
Re: Generating a random number for damage
Sorry, I had typed mathf a couple times in my previous reply (now fixed). In Lua, it's math.random, not mathf.random.
Re: Generating a random number for damage
So I'm trying to do but it's not changing the default variable value (0). I put it in the "script" area, is that not where I'm supposed to put it?
Code: Select all
Variable["BaseDamage"] = mathf.random(1, 4);
Re: Generating a random number for damage
Remove the "f" from mathf. Sorry, I had typed it wrong in my first reply.