Quax456 Posted October 23, 2012 Posted October 23, 2012 I have made a table with random tasks. In this case the starting flags for this task. I have found it by my self "tostring()" but the function doesn't raise the flag as it should do.... I have slmod installed maybe this cause the error??? My Rig: Windows 11 Pro, Intel i7-13700k@5.4GHz, 64GB DDR5 5200 RAM, Gigabyte Z790 AORUS Elite AX, 2TB Samsung 990 PRO, RTX4080, Thrustmaster HOTAS WARTHOG Stick + WINWING ORION 2 + MFG Crosswinds, LG 32" 4K 60FPS, ACER 30" 4K 60FPS GSync Display, HP Reverb G2 V2
Grimes Posted October 24, 2012 Posted October 24, 2012 Can you post the code? The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Quax456 Posted October 24, 2012 Posted October 24, 2012 It's the same code designed by Druid..... Stage1: -- Initialise table -- Change the values in the 2 variables lowest_flag and highest_flag to the flag values you wish to use in your mission local lowest_flag = 3001 local highest_flag = 3007 -- DO NOT EDIT BELOW THIS LINE-- local total_flags = 1 + (highest_flag - lowest_flag) random_flag_table = {} random_temp_table = {} for x = 1, total_flags do random_temp_table[x] = lowest_flag + (x-1) end Stage2: 7 times where index raises up to value of 7 local index = 1 table.insert(random_flag_table,random_temp_table[index]) table.remove(random_temp_table,index) Stage3: Get Flag out of the table and set them to true trigger.action.setUserFlag(tostring(random_flag_table[1]), true) -- then remove it from the table table.remove(random_flag_table, 1) But the flag doesn't get set to true, I verified it via slmod chat_cmd and the action works but not with the scripting above :( My Rig: Windows 11 Pro, Intel i7-13700k@5.4GHz, 64GB DDR5 5200 RAM, Gigabyte Z790 AORUS Elite AX, 2TB Samsung 990 PRO, RTX4080, Thrustmaster HOTAS WARTHOG Stick + WINWING ORION 2 + MFG Crosswinds, LG 32" 4K 60FPS, ACER 30" 4K 60FPS GSync Display, HP Reverb G2 V2
ajax Posted October 24, 2012 Posted October 24, 2012 If you copied and pasted the code into your post, then there is an error in stage 3: trigger.action.setUserFlag(tostring(random_flag_[color=Red]ta ble[/color][1]), true) Delete the extraneous space.
Quax456 Posted October 24, 2012 Posted October 24, 2012 If you copied and pasted the code into your post, then there is an error in stage 3: trigger.action.setUserFlag(tostring(random_flag_[color=Red]ta ble[/color][1]), true) Delete the extraneous space. No it jzst happens due to copy+paste, there is no space gap, sorry:D My Rig: Windows 11 Pro, Intel i7-13700k@5.4GHz, 64GB DDR5 5200 RAM, Gigabyte Z790 AORUS Elite AX, 2TB Samsung 990 PRO, RTX4080, Thrustmaster HOTAS WARTHOG Stick + WINWING ORION 2 + MFG Crosswinds, LG 32" 4K 60FPS, ACER 30" 4K 60FPS GSync Display, HP Reverb G2 V2
Druid_ Posted October 24, 2012 Posted October 24, 2012 Stage3: Get Flag out of the table and set them to true trigger.action.setUserFlag(tostring(random_flag_table[1]), true) -- then remove it from the table table.remove(random_flag_table, 1) But the flag doesn't get set to true, I verified it via slmod chat_cmd and the action works but not with the scripting above :( Don't need to use tostring. trigger.action.setUserFlag(random_flag_table[1], true) Now we have the scripting engine there should be a neater way of creating a random table than the method I used previously. When I have some time I shall have a think about it. i7-7700K : 16Gb DDR4 2800 Mhz : Asus Mobo : 2TB HDD : Intel 520 SSD 240gb : RTX 2080ti: Win10 64pro : Dx10 : TrackiR4 : TM Warthog : ASUS ROG SWIFT PG348Q
Quax456 Posted October 24, 2012 Posted October 24, 2012 (edited) Don't need to use tostring. trigger.action.setUserFlag(random_flag_table[1], true) Now we have the scripting engine there should be a neater way of creating a random table than the method I used previously. When I have some time I shall have a think about it. This will throw an exception cause DCS is awaiting as declared for this function a "STRING" for userflagname!!!!!!!! I have tested it otherwise I had not asked!!!!! :megalol: *EDIT:* Just forgett my issue have found the failure. Due to the absolutly great ME and the scripting windows there must be the error. I executet it via do script file and all works fine...... Big thanx for your support. Edited October 24, 2012 by Quax456 My Rig: Windows 11 Pro, Intel i7-13700k@5.4GHz, 64GB DDR5 5200 RAM, Gigabyte Z790 AORUS Elite AX, 2TB Samsung 990 PRO, RTX4080, Thrustmaster HOTAS WARTHOG Stick + WINWING ORION 2 + MFG Crosswinds, LG 32" 4K 60FPS, ACER 30" 4K 60FPS GSync Display, HP Reverb G2 V2
Grimes Posted October 24, 2012 Posted October 24, 2012 Its not perfect, but it works. Run the top code first. do -- Initialise table -- Change the values in the 2 variables lowest_flag and highest_flag to the flag values you wish to use in your mission local lowest_flag = 3 local highest_flag = 21 -- DO NOT EDIT BELOW THIS LINE-- local possible_flags = {} for i = lowest_flag, highest_flag do table.insert(possible_flags, i) end Flags = { pickRandom = function() if #possible_flags > 0 then local index = math.random(#possible_flags) trigger.action.setUserFlag(possible_flags[index], true) table.remove(possible_flags, index) end end, } end Every time you want to randomly pick something, run this code: Flags.pickRandom() See attached mission for an example.random_script.miz The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Druid_ Posted October 25, 2012 Posted October 25, 2012 The trouble is that Local index = math.random(#possible_flags) Without seeding math.random with a random number first will always allocate the tasks in the same order. Maybe you forgot as I know we have been discussing this in the past. This is why my method used ME triggers to randomise and call the lua code. Trouble is, it's messy and uses up a bunch of triggers to do so i7-7700K : 16Gb DDR4 2800 Mhz : Asus Mobo : 2TB HDD : Intel 520 SSD 240gb : RTX 2080ti: Win10 64pro : Dx10 : TrackiR4 : TM Warthog : ASUS ROG SWIFT PG348Q
Grimes Posted October 25, 2012 Posted October 25, 2012 Yes I am aware of that limitation. I've honestly just been using the default seed anyways in the scripts that I am building because it is simply good enough for testing. However when I ran a print statement while building this script, it didn't do it in the same order. I realize its just anecdotal evidence between two different runnings of the script, but here are the results. 00075.836 UNKNOWN wWorld::initMissionScripting: 11 00076.810 UNKNOWN wWorld::initMissionScripting: 8 00077.809 UNKNOWN wWorld::initMissionScripting: 7 00078.815 UNKNOWN wWorld::initMissionScripting: 16 00079.800 UNKNOWN wWorld::initMissionScripting: 15 00080.823 UNKNOWN wWorld::initMissionScripting: 18 vs 00116.185 UNKNOWN wWorld::initMissionScripting: 18 00117.188 UNKNOWN wWorld::initMissionScripting: 14 00118.184 UNKNOWN wWorld::initMissionScripting: 9 00119.187 UNKNOWN wWorld::initMissionScripting: 3 00120.187 UNKNOWN wWorld::initMissionScripting: 12 00121.189 UNKNOWN wWorld::initMissionScripting: 19 The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Druid_ Posted October 26, 2012 Posted October 26, 2012 To test correctly you would have to run the script in DCS then reboot pc and run script again. i7-7700K : 16Gb DDR4 2800 Mhz : Asus Mobo : 2TB HDD : Intel 520 SSD 240gb : RTX 2080ti: Win10 64pro : Dx10 : TrackiR4 : TM Warthog : ASUS ROG SWIFT PG348Q
Megagoth1702 Posted October 28, 2012 Posted October 28, 2012 Grimes man... This is simply amazing! This is SO... GOD... DAMN... EASY with the script now! I am someone who has no idea of DCS scripting, I have always done the stuff with the ME, a clusterFK of triggers. Thank you so much man! [sIGPIC][/sIGPIC] System specs:2500k @ 4.6 GHz 8GB RAM HD7950 OC'd Win7 x64 Posting tracks to make your DCS better - attention bump incoming!
Grimes Posted October 28, 2012 Posted October 28, 2012 Thank Druid and Speed more. They've been at this scripting thing longer than I have been, besides I simply modified Druids script a little bit to create that. And its not perfect because its missing a random seed, which we don't have access to. http://en.wiki.eagle.ru/wiki/Simulator_Scripting_Engine_(DCS:_World_1.2.1) covers the functions available. It was just recently added to the sim. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Megagoth1702 Posted October 28, 2012 Posted October 28, 2012 Link gets me to an error... It's missing a ")". Yeah well I thank every single guy out there who knows that much more than I do and teaches me/supplies me with aaaawesome stuff for this sim. :) [sIGPIC][/sIGPIC] System specs:2500k @ 4.6 GHz 8GB RAM HD7950 OC'd Win7 x64 Posting tracks to make your DCS better - attention bump incoming!
Recommended Posts