Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Post by Jools »

I don't really understand what has changed wrt wreck handling in script killed(). I tried to change the return value from return (0) to return (corpsetype), but I still have the issue that a wreck is always produced. This is arm podger, which also couldn't be fixed by the cob_fixer.py script.

Here's the script: http://pastebin.com/ND60wnkf
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Post by hokomoko »

you miss a " return (corpsetype);" in the end of Killed() function
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Post by gajop »

You're not returning anything at the end of the function, if none of the if statements are true.

Also those callins function signatures seem noticeably different from Lua, are you sure they're correct?
See https://github.com/ZeroK-RTS/Zero-K/blo ... #L280-L295 : returning 2 shouldn't generate a wreck.
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Post by hokomoko »

gajop they're correct.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Post by Jools »

Hmmm, that fixes it but it makes it harder to do the corresponding replacements in the bos scripts, they are all like this.

Presumably the return (0); wasn't needed before, since the statement was the last statement in the script anyway and not returning anything was equal to returning false.

But why is that still not the case? The changelog says:
(none if omitted)
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Post by hokomoko »

changelog is incorrect as Cob automatically returns 0 if no return statement is present, and the engine for some reason treats a corpseType of 0 the same as 1.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Post by Kloot »

Presumably the return (0); wasn't needed before, since the statement was the last statement in the script anyway and not returning anything was equal to returning false.
Any "return 0" (or "return -123" or "return 42" or "return whatever") statement was ignored before in favor of the value assigned to corpsetype, unless the execution of Killed encountered a sleep (in which case it was the other way around).

changelog is incorrect as Cob automatically returns 0 if no return statement is present
Wrong, no return equals -1 for all threads. The difference is that whatever value gets left on the stack by Killed is now discarded.
the engine for some reason treats a corpseType of 0 the same as 1.
I'm still not sure if that's intentional.
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Post by hokomoko »

Kloot wrote:Wrong, no return equals -1 for all threads
That's technically correct, but Scriptor automatically returns 0 if no value is specified, so no return never happens.

The -1 thing is delayed return when a thread sleeps.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Post by Kloot »

I'm afraid I don't accept specific compiler shenanigans as sufficient grounds to claim the "changelog is incorrect"; at most it could be called incomplete.
no return never happens
"none if omitted" technically also applies to the case where a Killed function has not been defined at all (as BA found out), so it does.
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)

Post by hokomoko »

Kloot wrote:I'm afraid I don't accept specific compiler shenanigans as sufficient grounds to claim the "changelog is incorrect"; at most it could be called incomplete.
It's not a specific compiler's shenanigans, it's popular in VMs that all function calls have a return value which defaults to 0.
I'd bet that TA's cob VM implementation (which is very likely slimmer than spring) uses this model.

So spring's implementation allows the running of incomplete bytecode by having enough overhead to compensate.
Post Reply

Return to “Game Development”