OFP2 Editor: Art Blade's "debug message tool"

Started by Art Blade, October 30, 2009, 02:57:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Art Blade

Hello mission editors,

do you have code that doesn't w@&k? The mission doesn't exactly do what you want? Or do you simply want to trace your code?

Well, then, at the end of this post is a code snippet (tool) that will help you debug your mission code. It is easy to use, and fully customisable.

Even better, it will tell you where exactly in the code it halted the mission :) If the mission worked fine to the point when you got the debug message, you can just hit "ok" and the mission will go on until the next debug point is reached. Like that, you are able to trace your code. Since the mission halts on every debug point, you can easily switch to your editor and check the code.

Here a concrete example (out of a mission I'm working on)

function onArriveAtWaypointfn(helo, destination)
call="--== ARRIVALS ==--"
OFP:land(crew, comopt)
debugmsg(call)
end


produced this debug message:

[smg id=1603 align=center width=400]




If you write your own code in "level.lua" or the likes, you may have wished a couple of times already to find out what the heck went wrong with your mission code, or if and when the game actually uses certain parts of your code etc.

I wanted to be able to actually "see" where in the code I was at a certain moment of my mission, and even better, halt the mission at the same time so I could check the code in the editor. The tool can't actually correct code but it helps find the part that went wrong, as well as "confirm" parts that worked properly.

Now that I finally managed to code a tool that works exactly the way I wanted, I proudly present this tool to you and gladly share it with you. Just copy paste it into your code if you like, and I'd be quite happy if you left the comment lines in just as they are, for a little credit ;)


function onMissionStart()
call="start mission"
debug=0
debugmsg(call)
end

---------------------------------------------------------------------------------------------------------------
-- debug message tool by Art Blade
--
-- http://openworldgames.org/owg/forums/index.php?topic=1133.msg16801#msg16801
--
-- just declare debug=0 inside the function onMissionStart() so we have a valid local variable
-- insert the debug function after the missionstart function
-- declare call="message you want to see" inside the part of code you want to debug
-- perferably inside functions or if-then sections
-- then insert debugmsg(call) there where you want to know if your code works
-- has to be inside the same section the call="xxx" was placed so you get your info

function debugmsg(call) -- function "debugmsg" needs an input "call"
debug=debug+1 -- increases counter (amount of total messages)
msg=("Call # "..debug) -- parameter1 of popup
msg2=call -- parameter2 of popup
return OFP:showPopup(msg,msg2) -- this is what we want, a message
end
---------------------------------------------------------------------------------------------------------------


Here you would get a popup right after the game launched, reading

Call # 1
start mission




You can do even more with that function

for example you can put your text in it, instead of declaring "call":
debugmsg("just checking here")

or you can use a different variable to see what it contains
debugmsg(killer)

Whatever you use inside the brackets will be displayed in the popup. :)


I hope it makes your life easier :)


edits: typos.
[titlebar]Vision without action is a daydream. Action without vision is a nightmare.[/titlebar]What doesn't kill us, makes us weirder.

gvse

Thanks man!
And when shall we see your mission? :)

Art Blade

glad you like it :)

By the way, try exchange msg with msg2. Then the description of the halting point will be big and the call # small. Good as long as your description isn't too long (else, gets cut off then)


msg2= ("Call # "..debug)
msg=call


The mission? "it's ready when it's ready"  ;D No idea, mate.

I'm only happy I start to understand LUA better and better (been only a week since I really started to learn the editor and coding in LUA) and at this stage it is more important for me to get the coding right. The mission itself is like a byproduct at the moment. I am experimenting a lot :)

[titlebar]Vision without action is a daydream. Action without vision is a nightmare.[/titlebar]What doesn't kill us, makes us weirder.

gvse

OK. I invariably return to the editor whenever the multiplayer aspect gets too frustrating. You know, I used to spend more time planning a mission in A2 than actually playing it, and it's the opposite in DR; that's how exciting the gameplay is for me.

Art Blade

the gameplay is great :) Actually, currently I am only busy with OFP2 SP (I don't play MP).

What I do is, getting into LUA for OFP2. That is almost as exciting :) I got a few custom made missions off the net just to check parts of their code, then go back every once and then to CM's example missions, and analyse that code. The main time I spend optimising the code of my mission. I enjoy it when the code works the way I intended it to; and if it doesn't, it is exciting to find out what the heck went wrong. Or better, why it went wrong. When I finally fixed it, then I felt like having won a combat. Of course I play the mission and wonder what could be added, removed, or changed, to make it better. Like that, the game keeps me quite busy and it is fun :)
[titlebar]Vision without action is a daydream. Action without vision is a nightmare.[/titlebar]What doesn't kill us, makes us weirder.

Tags:
🡱 🡳

Similar topics (5)