abdalaziz Posted March 16, 2019 Posted March 16, 2019 (edited) أنا هذا الكود الي عندي function initTraffic() last_yield = getTickCount() initTrafficMap() loadPaths() calculateNodeLaneCounts() loadZOffsets() initAI() initTrafficGenerator() traffic_initialized = true end function startTrafficInitialization() traffic_initialization = coroutine.create(initTraffic) keepLoadingTraffic() end addEventHandler("onResourceStart",resourceRoot,startTrafficInitialization) function keepLoadingTraffic() if traffic_initialized then traffic_initialized = nil last_yield = nil return end coroutine.resume(traffic_initialization) -- الديبق بهذا السطر -- cannot resume dead coroutine [string "?"] setTimer(keepLoadingTraffic,50,1) end function checkThreadYieldTime() local this_time = getTickCount() if this_time-last_yield >= 4000 then coroutine.yield() last_yield = this_time end end في هذا السطر وانا حددته في الكود فوق , coroutine.resume(traffic_initialization) بيجيني بلديبق هذا الخطأ : cannot resume dead coroutine [string "?"] ليش ؟؟ وإيش السبب ؟؟ وين المشكلة .. ومشكوور .. Edited March 16, 2019 by abdalaziz
KillerX Posted March 16, 2019 Posted March 16, 2019 coroutines مالي خبرة في بس جرب دا function initTraffic() last_yield = getTickCount() initTrafficMap() loadPaths() calculateNodeLaneCounts() loadZOffsets() initAI() initTrafficGenerator() traffic_initialized = true end function startTrafficInitialization() traffic_initialization = coroutine.create(initTraffic) keepLoadingTraffic() end addEventHandler("onResourceStart",resourceRoot,startTrafficInitialization) function keepLoadingTraffic() if traffic_initialized then traffic_initialized = nil last_yield = nil return end if( coroutine.status( traffic_initialization ) ~= "dead" ) then coroutine.resume(traffic_initialization) -- الديبق بهذا السطر -- cannot resume dead coroutine [string "?"] setTimer(keepLoadingTraffic,50,1) end end function checkThreadYieldTime() local this_time = getTickCount() if this_time-last_yield >= 4000 then coroutine.yield() last_yield = this_time end end 1 1
abdalaziz Posted March 18, 2019 Author Posted March 18, 2019 On 16/03/2019 at 15:38, KillerX said: coroutines مالي خبرة في بس جرب دا function initTraffic() last_yield = getTickCount() initTrafficMap() loadPaths() calculateNodeLaneCounts() loadZOffsets() initAI() initTrafficGenerator() traffic_initialized = true end function startTrafficInitialization() traffic_initialization = coroutine.create(initTraffic) keepLoadingTraffic() end addEventHandler("onResourceStart",resourceRoot,startTrafficInitialization) function keepLoadingTraffic() if traffic_initialized then traffic_initialized = nil last_yield = nil return end if( coroutine.status( traffic_initialization ) ~= "dead" ) then coroutine.resume(traffic_initialization) -- الديبق بهذا السطر -- cannot resume dead coroutine [string "?"] setTimer(keepLoadingTraffic,50,1) end end function checkThreadYieldTime() local this_time = getTickCount() if this_time-last_yield >= 4000 then coroutine.yield() last_yield = this_time end end شكراا عندي مشكلة واحدة بهذا الكود : function loadPathMapFile(filename) local file = fileOpen(filename,true) if not file then outputDebugString("Failed to open path map file: "..filename,2) return end local header_bytes = fileRead(file,12) if #header_bytes ~= 12 then outputDebugString("Failed to read the header of path map file: "..filename,2) fileClose(file) return end local node_ids,conn_ids = {},{} local nodecount,conncount,forbcount = bytesToData("3i",header_bytes) for nodenum = 1,nodecount do local node_bytes = fileRead(file,16) if #node_bytes ~= 16 then outputDebugString("Failed to read all nodes from path map file: "..filename,2) fileClose(file) return end local new_id = #node_z+1 node_ids[nodenum] = new_id local x,y,z,rx,ry = bytesToData("3i2s",node_bytes) node_x[new_id],node_y[new_id],node_z[new_id] = x/1000,y/1000,z/1000 node_rx[new_id],node_ry[new_id] = rx/1000,ry/1000 node_conns[new_id] = {} checkThreadYieldTime() end for connnum = 1,conncount do local conn_bytes = fileRead(file,20) if #conn_bytes ~= 20 then outputDebugString("Failed to read all connections from path map file: "..filename,2) fileClose(file) return end local new_id = #conn_type+1 conn_ids[connnum] = new_id local n1,n2,nb,trtype,lit,speed,ll,rl,density = bytesToData("3i2ubus2ubus",conn_bytes) local lit1,lit2 = lit%4,math.floor(lit/4) n1,n2 = node_ids[n1],node_ids[n2] conn_n1[new_id],conn_n2[new_id] = n1,n2 conn_nb[new_id] = nb ~= -1 and node_ids[nb] or nil conn_type[new_id] = trtype == 1 and "peds" or trtype == 2 and "cars" or trtype == 3 and "boats" or trtype == 4 and "planes" conn_light1[new_id] = lit1 == 1 and "NS" or lit1 == 2 and "WE" or lit1 == 3 and "ped" or nil conn_light2[new_id] = lit2 == 1 and "NS" or lit2 == 2 and "WE" or lit2 == 3 and "ped" or nil conn_maxspeed[new_id] = speed/10 conn_lanes.left[new_id],conn_lanes.right[new_id] = ll,rl conn_density[new_id] = density/1000 conn_forbidden[new_id] = {} if rl ~= 0 or ll == 0 then node_conns[n1][n2] = new_id end -- attempt to index field '?' (a nil value) [string "?"] -- هنا الديبق if ll ~= 0 or rl == 0 then node_conns[n2][n1] = new_id end addConnToTrafficMap(new_id) checkThreadYieldTime() end for forbnum = 1,forbcount do local forb_bytes = fileRead(file,8) if #forb_bytes ~= 8 then outputDebugString("Failed to read all forbidden connection sequences from path map file: "..filename,2) fileClose(file) return end local c1,c2 = bytesToData("2i",forb_bytes) conn_forbidden[conn_ids[c1]][conn_ids[c2]] = true checkThreadYieldTime() end fileClose(file) return true end فـ وين المشكلة ؟؟ if rl ~= 0 or ll == 0 then node_conns[n1][n2] = new_id end -- attempt to index field '?' (a nil value) [string "?"]
Master_MTA Posted March 18, 2019 Posted March 18, 2019 1 hour ago, abdalaziz said: @Master_MTA بدل التحققين بكذا if (rl ~= 0 or ll == 0) and n1 and n2 then node_conns[n1][n2] = new_id end -- attempt to index field '?' (a nil value) [string "?"] -- هنا الديبق if (ll ~= 0 or rl == 0)and n1 and n2 then node_conns[n2][n1] = new_id end بالتوفيق 1
abdalaziz Posted March 23, 2019 Author Posted March 23, 2019 On 18/03/2019 at 13:05, Master_MTA said: بدل التحققين بكذا if (rl ~= 0 or ll == 0) and n1 and n2 then node_conns[n1][n2] = new_id end -- attempt to index field '?' (a nil value) [string "?"] -- هنا الديبق if (ll ~= 0 or rl == 0)and n1 and n2 then node_conns[n2][n1] = new_id end بالتوفيق if (ll ~= 0 or rl == 0) and n1 and n2 then node_conns[n2][n1] = new_id end -- ')' expected near ' ')' expected near ' وش الحل وسويتها كذا,نفس الديبق if ( ll ~= 0 or rl == 0 ) and n1 and n2 then -- ')' expected near ' node_conns[n2][n1] = new_id end
Master_MTA Posted March 23, 2019 Posted March 23, 2019 4 hours ago, abdalaziz said: @Master_MTA في خطا بالسينتكس حق الفنكشن حاول تراجع الفنكشن من اوله لاخره وشيك على الساينتكس 1
abdalaziz Posted March 24, 2019 Author Posted March 24, 2019 function loadPathMapFile(filename) local file = fileOpen(filename,true) if not file then outputDebugString("Failed to open path map file: "..filename,2) return end local header_bytes = fileRead(file,12) if #header_bytes ~= 12 then outputDebugString("Failed to read the header of path map file: "..filename,2) fileClose(file) return end local node_ids,conn_ids = {},{} local nodecount,conncount,forbcount = bytesToData("3i",header_bytes) for nodenum = 1,nodecount do local node_bytes = fileRead(file,16) if #node_bytes ~= 16 then outputDebugString("Failed to read all nodes from path map file: "..filename,2) fileClose(file) return end local new_id = #node_z+1 node_ids[nodenum] = new_id local x,y,z,rx,ry = bytesToData("3i2s",node_bytes) node_x[new_id],node_y[new_id],node_z[new_id] = x/1000,y/1000,z/1000 node_rx[new_id],node_ry[new_id] = rx/1000,ry/1000 node_conns[new_id] = {} checkThreadYieldTime() end for connnum = 1,conncount do local conn_bytes = fileRead(file,20) if #conn_bytes ~= 20 then outputDebugString("Failed to read all connections from path map file: "..filename,2) fileClose(file) return end local new_id = #conn_type+1 conn_ids[connnum] = new_id local n1,n2,nb,trtype,lit,speed,ll,rl,density = bytesToData("3i2ubus2ubus",conn_bytes) local lit1,lit2 = lit%4,math.floor(lit/4) n1,n2 = node_ids[n1],node_ids[n2] conn_n1[new_id],conn_n2[new_id] = n1,n2 conn_nb[new_id] = nb ~= -1 and node_ids[nb] or nil conn_type[new_id] = trtype == 1 and "peds" or trtype == 2 and "cars" or trtype == 3 and "boats" or trtype == 4 and "planes" conn_light1[new_id] = lit1 == 1 and "NS" or lit1 == 2 and "WE" or lit1 == 3 and "ped" or nil conn_light2[new_id] = lit2 == 1 and "NS" or lit2 == 2 and "WE" or lit2 == 3 and "ped" or nil conn_maxspeed[new_id] = speed/10 conn_lanes.left[new_id],conn_lanes.right[new_id] = ll,rl conn_density[new_id] = density/1000 conn_forbidden[new_id] = {} if ( rl ~= 0 or ll == 0 ) and n1 and n2 then node_conns[n1][n2] = new_id end if ( ll ~= 0 or rl == 0 ) and n1 and n2 then node_conns[n2][n1] = new_id end -- ')' expected near ' addConnToTrafficMap(new_id) checkThreadYieldTime() end for forbnum = 1,forbcount do local forb_bytes = fileRead(file,8) if #forb_bytes ~= 8 then outputDebugString("Failed to read all forbidden connection sequences from path map file: "..filename,2) fileClose(file) return end local c1,c2 = bytesToData("2i",forb_bytes) conn_forbidden[conn_ids[c1]][conn_ids[c2]] = true checkThreadYieldTime() end fileClose(file) return true end خلاص لقيت المشكلة وحليتها كانت مشكلة سخيفة . شكراً لكن المشكلة هنا هي , انا عندي هذا الكود local n1,n2,nb = conn_n1[connid],conn_n2[connid],conn_nb[connid] local x1,y1 = node_x[n1],node_y[n1] local x2,y2 = node_x[n2],node_y[n2] local density = conn_density[connid] do local lanes = conn_lanes.left[connid]+conn_lanes.right[connid] density = density*(lanes == 0 and 1 or lanes) end local SQUARE_SIZE = SQUARE_SIZE local getDistanceBetweenPoints2D = getDistanceBetweenPoints2D local addConnToSquare = addConnToSquare local math_min,math_max = math.min,math.max local math_floor,math_ceil = math.floor,math.ceil local math_abs,math_huge = math.abs,math.huge if nb then local bx,by = node_x[nb],node_y[nb] local mxx , mxy , myx , myy = x1 - bx , y1 - by , x2 - bx , y2 - by -- attempt to perform arithmetic on local 'x' (a nil value) [string "?"] الخطأ هنا .. ماشوف انا انه في غلط .. ليش ؟؟ وايش الغلط ؟ local mxx , mxy , myx , myy = x1 - bx , y1 - by , x2 - bx , y2 - by -- attempt to perform arithmetic on local 'x' (a nil value) [string "?"] attempt to perform arithmetic on local 'x' (a nil value) [string "?"]
Master_MTA Posted March 24, 2019 Posted March 24, 2019 55 minutes ago, abdalaziz said: arithmetic مافي متغير اسمه اكس اصلا تحقق من رقم السطر
abdalaziz Posted March 24, 2019 Author Posted March 24, 2019 9 hours ago, Master_MTA said: مافي متغير اسمه اكس اصلا تحقق من رقم السطر x1 مب x أخطأت ..
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