I’m trying to make a system that every time a function is called I get a different value from math.random.
I’m using this to get a different attacks for NPCs in a turn-based RPG game but I have no idea how to set up a loop that gets me a different value.
I tried for loops, repeat until loops and I get 2 different outcomes
1 - it repeats the attack over and over
2 - it doesn’t do anything while the attack is supposed to run
I have since removed the loops to hopefully be easier to understand
code –
function enemyMovePicked()
local event_index = math.random(#enemyMoveSetRandom.enemy)
local event = enemyMoveSetRandom.enemy[event_index]
local event_f = event.attack
if chosen ~= event.ATTACK_NAME and stop == false then
event_f()
stop = true
wait(1)
stop = false
end
chosen = event.ATTACK_NAME
end
(enemyMoveSetRandom is a module script)
How would I do it in a way to get a different outcome?
Code examples or fixed versions will appreciated!