DakiLLa Posted February 22, 2009 Share Posted February 22, 2009 hi. i have one problem here... well, i have a table with objects. How to get randomly an object and make with him some operations? lets suppose something like this: 'board from fallout' rows = 10 columns = 10 board = {} local count = 0 function createBoard () for i = 1,rows do for j = 1, columns do board[count] = createObject ( 1697, -2274.5741875 + 4.466064 * j, 1858.0903320313 + 5.362793 * i, 102.6078, math.deg( 0.555 ), 0, 0 ) count = count + 1 end end end addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), createBoard ) and i want to attach a marker to one of these blocks (randomly). function test () rndBlock = math.random (1, #board) m_block = board[rndBlock] m = createMarker ( 0, 0, 0, "corona", 2.0, randInt(0,255), randInt(0,255), randInt(0,255), 150 ) attachElementToElement ( m, m_block ) end addCommandHandler ( "test", test ) but something wrong, i dont know how to make it..can you help ? Link to comment
robhol Posted February 22, 2009 Share Posted February 22, 2009 I'm noticing that lots of people here are extremely good at giving loads and loads of info. Do you get any errors? Link to comment
DakiLLa Posted February 22, 2009 Author Share Posted February 22, 2009 I'm noticing that lots of people here are extremely good at giving loads and loads of info. oh, ye, i see it too.. but sorry, my mistake well, i have nothing when i write 'test' command.. no errors, no warnings.. Link to comment
robhol Posted February 22, 2009 Share Posted February 22, 2009 Hmm... I can't really spot any mistakes, but you might want to change the color thingies to, say, a minimum of 100. So, 100 + math.random(1,155), since a marker with 0,0,0 will not be black, but invisible. I don't know how many times you tried, but this can also be the reason you didn't see anything. Link to comment
DakiLLa Posted February 22, 2009 Author Share Posted February 22, 2009 lol, really working perfect.. i've just tryed to create an object and attach it to block and it works.. well, may be i will have some questions later, so, thx rob anyway Link to comment
DakiLLa Posted February 22, 2009 Author Share Posted February 22, 2009 well another question. If i want to destroy block then i need to remove it from table as i think cse i have warnings when i try to destroy it again (object destroyed, but not removed from table so, you cant destroy nothing). How to do this ? (with my examples ofcourse, with board { } table..) Link to comment
Ace_Gambit Posted February 22, 2009 Share Posted February 22, 2009 function destroy ( wut ) for i = #board, 1, -1 do if ( board[ i ] == wut ) then destroyElement ( board[ i ] ) table.remove ( board, i ) break end end end Link to comment
DakiLLa Posted February 23, 2009 Author Share Posted February 23, 2009 yee, thx ace, thats what i need Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now