Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make math.random print a string

Tags:

lua

how do you make math.random print a string and not an int value from a table.

this is some of the code I wrote

local Menu = {"🍕","🍟","🍔"}

local Item = math.random(1,#Menu)

print(Item)

Sorry if this is a question if like everyone knows. I just started scripting about 6 days ago. I coudnt find the answer anywhere on google so I decided to come here.

like image 937
Nneka Avatar asked Aug 12 '26 14:08

Nneka


1 Answers

You are close: using print(Menu[Item]) should do what you need.

You can also use math.random(#Menu), as it's the same as math.random(1,#Menu).

like image 114
Paul Kulchenko Avatar answered Aug 14 '26 10:08

Paul Kulchenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!