Page 1 of 1
Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)
Posted: 29 Feb 2016, 10:52
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
Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)
Posted: 29 Feb 2016, 10:58
by hokomoko
you miss a " return (corpsetype);" in the end of Killed() function
Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)
Posted: 29 Feb 2016, 11:04
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.
Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)
Posted: 29 Feb 2016, 11:16
by hokomoko
gajop they're correct.
Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)
Posted: 29 Feb 2016, 11:30
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)
Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)
Posted: 29 Feb 2016, 11:53
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.
Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)
Posted: 29 Feb 2016, 12:14
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.
Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)
Posted: 29 Feb 2016, 12:40
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.
Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)
Posted: 29 Feb 2016, 14:03
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.
Re: COB: always use the return value of the Killed thread to determine wreck level (none if omitted)
Posted: 29 Feb 2016, 16:01
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.