maarten123 Posted September 12, 2010 Share Posted September 12, 2010 (edited) hi, now i have make a script to check the map on DD/DM now this script check if there is a vehicle that is a hunter addEventHandler("onMapStarting", root, function(mapInfo, mapOptions, gameOptions) if #getElementsByType ( "checkpoint" ) == 0 then -- checking DD/DM map for i, pu in pairs ( getElementsByType ( "racepickup" ) ) do if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then maptype = "DM" else maptype = "DD" end end outputChatBox(getPlayerName(source).."*this is a"..tostring(maptype).." map",getRootElement(),0,255,0) end end ) But now he always saying This is a DD map Can anyone help me out? Greetings Maarten123 EDIT: line 2 Edited September 12, 2010 by Guest Link to comment
dzek (varez) Posted September 12, 2010 Share Posted September 12, 2010 becouse it reset this to "dd" on another pickup. do it like this: addEventHandler("onMapStarting", root, function(mapInfo, mapOptions, gameOptions) local hunterFound = false for i, pu in pairs ( getElementsByType ( "racepickup" ) ) do if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then hunterFound = true end end if hunterFound then maptype = "DM" else maptype = "DD" end outputChatBox(getPlayerName(source).."*this is a"..tostring(maptype).." map",getRootElement(),0,255,0) end ) edit: ive only checked/fixed the logic of script!, not if these lines: if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then are valid and doing what they should Link to comment
maarten123 Posted September 12, 2010 Author Share Posted September 12, 2010 becouse it reset this to "dd" on another pickup.do it like this: addEventHandler("onMapStarting", root, function(mapInfo, mapOptions, gameOptions) local hunterFound = false for i, pu in pairs ( getElementsByType ( "racepickup" ) ) do if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then hunterFound = true end end if hunterFound then maptype = "DM" else maptype = "DD" end outputChatBox(getPlayerName(source).."*this is a"..tostring(maptype).." map",getRootElement(),0,255,0) end ) edit: ive only checked/fixed the logic of script!, not if these lines: if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then are valid and doing what they should sorry also don't work Again the same issue Link to comment
dzek (varez) Posted September 12, 2010 Share Posted September 12, 2010 try Debugging your script. Read this carefully - you will need this many times. especially outputDebugString Link to comment
maarten123 Posted September 12, 2010 Author Share Posted September 12, 2010 try Debugging your script.Read this carefully - you will need this many times. especially outputDebugString yes i know what debugscript is, i use it but there is not a error or waring the only point is that he said it's alway a DD (also in DM maps) script: addEventHandler("onMapStarting", root, function(mapInfo, mapOptions, gameOptions) if #getElementsByType ( "checkpoint" ) == 0 then -- checking DD/DM map local hunterFound = false for i, pu in pairs ( getElementsByType ( "racepickup" ) ) do if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then hunterFound = true end end if hunterFound then maptype = "DM" else maptype = "DD" end outputChatBox("*this is a "..tostring(maptype).." map",getRootElement(),0,255,0) end end ) Link to comment
dzek (varez) Posted September 13, 2010 Share Posted September 13, 2010 GOD! ! Read WHOLE wiki page I've sent you! Debugscript command is only small part in the art of debugging. Read especially that part about outputDebugString. Link to comment
maarten123 Posted September 13, 2010 Author Share Posted September 13, 2010 GOD! ! Read WHOLE wiki page I've sent you! Debugscript command is only small part in the art of debugging. Read especially that part about outputDebugString. oh sorry script: addEventHandler("onMapStarting", root, function(mapInfo, mapOptions, gameOptions) if #getElementsByType ( "checkpoint" ) == 0 then -- if 1 outputDebugString("entered if1") local hunterFound = false for i, pu in pairs ( getElementsByType ( "racepickup" ) ) do -- for1 outputDebugString("entered for1") if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then -- if2 outputDebugString("entered if2") hunterFound = true end end if hunterFound then maptype = "DM" else maptype = "DD" end outputChatBox("*this is a "..tostring(maptype).." map",getRootElement(),0,255,0) end end ) you means like this? so this is the result: 0times : entered if2 1times : entered if 1 number of vehicleschanges times: entered for1 Link to comment
dzek (varez) Posted September 13, 2010 Share Posted September 13, 2010 much better you can do also: outputDebugString(getElementData (pu, "type").." --- "..getElementData (pu, "vehicle")) oh! i just realized that getElementData from map file will probably return string for all values. this means for numebrs too. so "425" (string) will never equal to 425 (integer) ! getElementData(pu, "vehicle") is probably returning "425" and getVehicleModelFromName is returning 425 (number) for sure. if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == tostring(getVehicleModelFromName ("Hunter")) then -- if2 if you will do debug with displaying each value - you will easly see that Link to comment
Puma Posted September 13, 2010 Share Posted September 13, 2010 You're wrong. if hunterFound then maptype = "DM" else maptype = "DD" end You're checkin if hunterFound is nil. It can only be false or true (since it is defined as false and maybe defined as true later in the script), so you should be checking: if hunterFound == true then maptype = "DM" else maptype = "DD" end Link to comment
dzek (varez) Posted September 13, 2010 Share Posted September 13, 2010 wut? if variable then outputChatBox("1") end will output 1 if variable equals to true. will not output if variable is nil or false. It's logical: if true then outputChatBox("1") end -- will always output if false then outputChatBox("1") end -- will never output -- logical eh? -- "if" conditional is passing when after "parsing" all checks the results is "true" - it's standard across all coding languages Link to comment
Puma Posted September 14, 2010 Share Posted September 14, 2010 Maarten told me on Xfire that the stuff I posted here worked... Link to comment
maarten123 Posted September 19, 2010 Author Share Posted September 19, 2010 Maarten told me on Xfire that the stuff I posted here worked... hahahah, yes sorry for my late post, thanks for help varez 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