local t, i = {"test", "testing", "test123"}, 1
function onThink(interval)
broadcastMessage(t[i], MESSAGE_STATUS_WARNING)
i = i == #t and 1 or i + 1
return true
end
Mind showing me how the globalevents.lua line should be for this one because mine just keeps saying failed to execute event Broadcast Im wondering if it has to have a certain name, This is what I have it as and the broadcast.lua is your code exactly ^ (running tfs 1.1)Code:local t, i = {"test", "testing", "test123"}, 1 function onThink(interval) broadcastMessage(t[i], MESSAGE_STATUS_WARNING) i = i == #t and 1 or i + 1 return true end
-- [( Script created by gboxx )] --
function onThink(interval, lastExecution)
MENSAGE = {
"[Event Mensaje]xxxx",
"[Event Mensaje]xxxx",
}
broadcastMessage(MENSAGE[math.random(1,#MENSAGE)],20)
return TRUE
end
PHP:-- [( Script created by gboxx )] -- function onThink(interval, lastExecution) MENSAGE = { "[Event Mensaje]xxxx", "[Event Mensaje]xxxx", } broadcastMessage(MENSAGE[math.random(1,#MENSAGE)],20) return TRUE end
but it doesn't give same valueIndentation, MESSAGE is global, it should be local, TRUE should be true, if you are using math.random you need a seed for it, otherwise it will always return the same value.
but it doesn't give same value
i don't understand you what is seed and too tired to read google wall of text about it.Try it yourself, you need a seed for random values, thats the point of the seed function. Google it
i don't understand you what is seed and too tired to read google wall of text about it.
Without testing i say: his code is working perfectly.
print(math.random(100))
umm... you are using totally different math.ranom, ofc you get 1 value..
he is taking random string from table.
EDIT: i did test the lua.org thing you have there, its kinda broken..
print(math.random(100))
should give random value between 1 and 100 if i remember correctly
math.randomseed(os.time())
print(math.random(100))
no need, it should already work by just printing 1 line without seedingIt is actually not broken.
Now try this:
Code:math.randomseed(os.time()) print(math.random(100))
As you can see all I did was add the seed function.
no need, it should already work by just printing 1 line without seeding
i dont have the seed somewhere else and it works just fine for me in TFS.So you checked the demo once again?
As you can see with the demo, if you don't use the seed you will get the same value, but if you use the seed you will get a random value.
A seed is required.
If you don't then you most likely have it somewhere else.
i dont have the seed somewhere else and it works just fine for me in TFS.
math.random() generates pseudo-random numbers uniformly distributed. Supplying argument alters its behaviour:Dude.. you have a seed somewhere, might be in the source code or in a lua file.
If we are talking about raw lua, then the demo is raw.
And atleast with older versions of tfs it was required to use the seed.
Just as the demo code showed.
math.random() generates pseudo-random numbers uniformly distributed. Supplying argument alters its behaviour:
i found this from LUA manual
- math.random() with no arguments generates a real number between 0 and 1.
- math.random(upper) generates integer numbers between 1 and upper.
- math.random(lower, upper) generates integer numbers between lower and upper.