Jump to content

math.random Help?


Lloyd Logan

Recommended Posts

Hey,

How would i create a script so that math.random(<--- I think its that) chooses from an array of Co-ordinates?

I know all the onPlayerWasted and stuff, but how would i make it the math.random chooses from a list of Co-ordinates?

addEventHandler( "onPlayerWasted", getRootElement( ), 
function() 
        setTimer( spawnPlayer, 2000, 1, source, 2745.5830078125, -1608.7109375, 290.84722900391 ) --How would I make math.random choose from a list of co-ordinates? 
    end 
) 

Link to comment

In the script, the length of the array is needed. So # was used to reach that goal. aPos is an array.

Array = {5, 5, 5}

#String OR #array makes lua replace that value at its point in the script with the current size of the box of data its next to. (In C id just call it an area of memory) Since Lua is Dynamically typed, # can determine for it self what kind of data types are in the variable its next to.

if h = string then return amount of bytes.

if its an array, return amount of elements or objects.

Arrays can be ever growing as well.

Array[4] = 5 would now add [4] = 5 to the array as well.

They can easily be deleted too by doing Array[4] = nil. Arrays are objects themselves too. In C++ you have classes, in Lua you can substitute that with Arrays.

For more information http://lua-users.org/wiki/TutorialDirectory

Link to comment
Please, Give that link a good skim. Twice even, i tell students to do this and the ones who do excel in the language.

Well Ghost, I can honestly say that I have only read it once, (it's too late for me to read it again, I also read the in depth tutorials) but I honestly feel I understand so much more about Lua, and when I was confused about the Arrays, I feel I know them inside out, bu lt once again the Link has improved me so much in the last hour or so and that's me read it for the first time!

Thank you!

Link to comment
No problem, my job here is to help teach others "how" to learn. Not, teach them what they want to learn. This helps users learn on their own, and saves them time asking questions when they can figure it out on their own by experience.

Or actually, it's not a job of yours, it's just a thing/hobby of yours. Unless you actually get paid :roll:

Link to comment

Jealousy is a bitter taste, isn't it?.

Your miss the idea of what a job is, a job is not always something you get paid for, my gain from this (or what you would call, pay) is the idea that others are learning. Please bomb a different thread with your off topic suggestions to the definition of what a word is.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...