Page 1 of 1
Generating a random number for damage
Posted: Sun Mar 01, 2020 2:01 pm
by AlexNerd
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
Posted: Sun Mar 01, 2020 2:08 pm
by Tony Li
Hi Alex,
Use the "math.random" function. Examples:
Code: Select all
Variable["Damage"] = math.random(1, 6)
or:
Re: Generating a random number for damage
Posted: Sun Mar 01, 2020 4:29 pm
by AlexNerd
Thank you! I wasn't sure if that function worked in lua
Re: Generating a random number for damage
Posted: Sun Mar 01, 2020 5:17 pm
by Tony Li
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
Posted: Sun Mar 01, 2020 7:33 pm
by AlexNerd
So I'm trying to do
Code: Select all
Variable["BaseDamage"] = mathf.random(1, 4);
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?
Re: Generating a random number for damage
Posted: Sun Mar 01, 2020 8:05 pm
by Tony Li
Remove the "f" from mathf. Sorry, I had typed it wrong in my first reply.