hackAssert()

For AI and campaign script related discussions and questions
Post Reply
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

hackAssert()

Post by aubergine »

I'm thinking of using hackAssert() more often in my code but before doing so wanted to clarify what exactly is a "game assert"?

Is it OK to enclose hackAssert() in a try..catch?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: hackAssert()

Post by Per »

What a game assert does depends on how the game was started. If you, like me, run it under a debugger, it will immediately halt and allow you to inspect the problem. Otherwise it will print an error and continue.

I do not know what try...catch will do. The function does throw a javascript error on failure...
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: hackAssert()

Post by aubergine »

That's good to know :)

I have some fringe cases in my "Test API" unit tests where in order to test the Test API I have to do some tests that will (or rather, should, if everything is working ok) fail. Because the assertions in Test API are all centrally defined, and there's no easy way for me to trap the expected error from within the test, it might lead to false game asserts -- is there some message I should associate with the assertion to indicate "this is supposed to fail"?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply