const randomEl = items[Math.floor(Math.random() * items.length)];
So if I understand you I would doCode:const randomEl = items[Math.floor(Math.random() * items.length)];
If you need me to explain this snippet, ask and I will let you know.
Also using let is better in JS if you are not going to use this variable in another code snipper as var has global scope and mess up other variables, if you are not sure which one to use and you dont have a lot of variables var is fine.
If the value wont change during runtime just use const
You are a life saver this worked perfectly for the random reward I was working on. Thank you.Code:const randomEl = items[Math.floor(Math.random() * items.length)];
If you need me to explain this snippet, ask and I will let you know.
Also using let is better in JS if you are not going to use this variable in another code snipper as var has global scope and mess up other variables, if you are not sure which one to use and you dont have a lot of variables var is fine.
If the value wont change during runtime just use const
So if I understand you I would do
let items =[1,2,3,4,5];
const randomEl = items[Math.floor(Math.random() * items.length)];
$gameParty.gainItem($dataItems[randomEl],1);
to reward the random item from the list. Am I understanding this correctly?
let items =[1,2,3,4,5];
$gameParty.gainItem($dataItems[items[Math.floor(Math.random() * items.length)]],1);
You are a life saver this worked perfectly for the random reward I was working on. Thank you.