What did I wrong?

I wanted to create a Script, where the Player who is writing “event” is going to See a number from 1-5.


random = {}

random[1] = 1
random[2] = 2
random[3] = 3

function event()
	print(math.random(random)
end

Now I tried only the random number function.

But there is not showing a number?

What did I wrong

[editline]11th January 2017[/editline]

Ok I found a misstake after random) I forgot")" but that didnt changes anything

Are you even calling the function “event”?


random = {}

random[1] = 1
random[2] = 2
random[3] = 3

function event()
	print(math.random(random))
end

print(event)

So? xD sorry im new at lua ;D

input:8: bad argument #1 to ‘random’ (number expected, got table)

This is showing on lua demo


random = {}

random[1] = 1
random[2] = 2
random[3] = 3

function event()
	print( random[math.random( 1, 3 )] )
end

event()

Its only showing “3” :frowning:

What does 1, 3 do? Counting all tables from 1 to 3? :smiley:

It’s supposed to pick a random number between 1 and 3. For some reason it’s only picking 3. Not quite sure why.

ok, so I dont need to do the random = {} thing?

You do need

, that’s what defines the table, without that, the 3 lines after it are useless.

The “random = {} thing” is you table from what you are picking a random value with
[lua]
random[math.random(1,3)]
[/lua]

Edit:
Well, posted too late. :c

ok, thanks!

I will try it with more numbers :smiley:

So new question:

Is there a way that when a Player is picking the Right number is getting Pointshop points?

This code is returning only the number 3…

I don’t know if i’m just being dumb or what, but it should generate a random number between 1 and 3…

:frowning:

Idk if i am dumb too, but i think the math.random() function doesnt work properly

For me this is only printing 10.

Bist du nicht von Suchtbunker? xD

[editline]11th January 2017[/editline]

:frowning: I wanted to create smth like an raffle

[editline]11th January 2017[/editline]

Everyone is typing a number between 1-25 and everyone who has the right number gets 500 Pointshop Points

The issue is with how the random number generator is seeded. If you use random multiple times in the same code you will get different numbers, but if you run it once, stop executing, run again etc. you will always get the same number the first time.

Completely forgot that… xD

So I can´t create a Raffle?

If you run the code in-game the math.random lib works as it should.