kevincouto6 Posted November 17, 2018 Share Posted November 17, 2018 Hello, Can someone help me here? createMarkerLocations1 = { [1] = {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, [2] = {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [3] = {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, [4] = {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [5] = {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations2 = { [1] = {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, [2] = {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [3] = {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, [4] = {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [5] = {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations3 = { [1] = {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, [2] = {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [3] = {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, [4] = {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [5] = {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations4 = { [1] = {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, [2] = {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [3] = {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, [4] = {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [5] = {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations5 = { [1] = {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, [2] = {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [3] = {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, [4] = {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [5] = {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } Could someone help me randomly create 5 markes 1 from each table ? Link to comment
Moderators Patrick Posted November 17, 2018 Moderators Share Posted November 17, 2018 (edited) -- table with custom indexed rows createMarkerLocations1 = { [1] = {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, [2] = {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [3] = {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, [4] = {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [5] = {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations2 = { [1] = {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, [2] = {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [3] = {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, [4] = {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [5] = {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations3 = { [1] = {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, [2] = {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [3] = {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, [4] = {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [5] = {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations4 = { [1] = {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, [2] = {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [3] = {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, [4] = {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [5] = {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations5 = { [1] = {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, [2] = {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [3] = {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, [4] = {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, [5] = {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } function getTableSize(t) local l = 0 for _ in pairs(t) do l = l + 1 end return l end function createRandomMarker(table) local tableSize = getTableSize(table) local randomRow = math.random(1,tableSize) local count = 1 for index, data in pairs(table) do if count == randomRow then return createMarker(data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9]) break end count = count + 1 end return false end local markerElement1 = createRandomMarker(createMarkerLocations1) -- create marker from table: createMarkerLocations1 local markerElement2 = createRandomMarker(createMarkerLocations2) -- create marker from table: createMarkerLocations2 local markerElement3 = createRandomMarker(createMarkerLocations3) -- create marker from table: createMarkerLocations3 local markerElement4 = createRandomMarker(createMarkerLocations4) -- create marker from table: createMarkerLocations4 local markerElement5 = createRandomMarker(createMarkerLocations5) -- create marker from table: createMarkerLocations5 But this is easier and better: -- table without custom indexed rows createMarkerLocations1 = { {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations2 = { {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations3 = { {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations4 = { {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } createMarkerLocations5 = { {228, 1877, 18 -1, "cylinder", 4, 0 ,255 ,0, 255}, {228, 1891, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, {226, 1904, 18 -1, "cylinder", 4, 255, 255, 0, 170}, {212, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170 }, {198, 1912, 18 -1, "cylinder", 4, 255, 255, 0, 170}, } function createRandomMarker(table) local randomRow = math.random(1,#table) return createMarker(table[randomRow][1], table[randomRow][2], table[randomRow][3], table[randomRow][4], table[randomRow][5], table[randomRow][6], table[randomRow][7], table[randomRow][8], table[randomRow][9]) end local markerElement1 = createRandomMarker(createMarkerLocations1) -- create marker from table: createMarkerLocations1 local markerElement2 = createRandomMarker(createMarkerLocations2) -- create marker from table: createMarkerLocations2 local markerElement3 = createRandomMarker(createMarkerLocations3) -- create marker from table: createMarkerLocations3 local markerElement4 = createRandomMarker(createMarkerLocations4) -- create marker from table: createMarkerLocations4 local markerElement5 = createRandomMarker(createMarkerLocations5) -- create marker from table: createMarkerLocations5 Edited November 17, 2018 by Patrick2562 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