Not logged inOpenClonk Forum
Up Topic Development / Developer's Corner / c1c542ea4b8c (C4Aul: Add new type 'nil')
- - By Günther [de] Date 2009-07-20 04:03
The new C4Value constructors look wrong: Set already calls AddDataRef(), calling it again will probably cause memory leaks. And DelDataRef is not designed to be called on undefined data. The constructor really has to do to the work itself.

Also, having C4Value::Set default to C4V_Nil doesn't seem save, there might be code which relies on CnvGuess. Better to remove the default entirely than this.

And I don't think we need a new type for this. As far as I can see, the only benefit is that false and zero the integer are distinct from zero the nullpointer. Zero the nullpointer can continue to use the type any. We should rather remove any uses of CnvGuess now that we don't need to load old savegames anymore.
Reply
Parent - - By Zapper [de] Date 2009-07-20 10:46

>the only benefit is that false and zero the integer are distinct from zero the nullpointer.


And a lot about parameters would change. Currently we have the problem that, for example, you cannot play a sound (via Sound()) only for the player with the number 0. Why? Because 0 means "for all" there. nil would make stuff like that a lot easier, because it would remove such ambiguities
Parent - - By Sven2 [de] Date 2009-07-20 12:29
First: You can. You specify PlayerNumber+1 for per-player sounds. Which is, of course, error-prone. But this is something we should fix by changing player numbers to start counting from 1. It's a change I wanted do do for a long time, but couldn't because of backwards compatibility.

Imo, adding another element of confusion is *not* helpful in this case. Because it would mean we'd have to change certain parameters to accept two possible types (in this case, integer and nil) and "nil" would have different meanings for different functions. It is much more straightforward to define constants of the correct type. In this case, it would be Sound(..., NO_OWNER); or you could make it something like Sound(..., SND_AllPlayers) if you wanted to. Other examples of this method include NoContainer/AnyContainer - something you can't do with nil, since there's only one nil.
Parent - By Isilkor Date 2009-07-22 08:02
NoContainer can be nil without any problems, and AnyContainer is just a relic from the days when we didn't have FindObject2.
Reply
Parent - - By Günther [de] Date 2009-07-20 13:07
Er, that's exactly what I said. And you don't need a new type for that, just not forcing all zeros to be of type any will get you that.
Reply
Parent - - By MrBeast [de] Date 2009-07-20 16:48
Then it should be possible to set wheter it is an any or an int. May a constant NIL which is an any 0?
Reply
Parent - By Isilkor Date 2009-07-22 08:04
There is now a constant nil which is (any)0. Entering 0 will net you (int)0.
Reply
Parent - - By Clonkonaut [de] Date 2009-07-21 19:01
Another benefit is that you can distinguish between a function with no return value (returning nil then) and a function returning 0.
Reply
Parent - - By Ape [fi] Date 2009-07-21 19:13
Isn't there void type functions for that?
Parent - By Clonkonaut [de] Date 2009-07-21 20:11
In C4Script? Nope?
Reply
Parent - By Günther [de] Date 2009-07-21 21:22 Edited 2009-07-21 21:31
No, that's also the same as "false and zero the integer are distinct from zero the nullpointer". Or at least a direct consequence. And it's not very useful, there are lots of values a function could have returned to indicate that it has a result that is not an integer.

Isilkor already addressed my concerns, nil now has type C4V_Any and the other problems are resolved.
Reply
Up Topic Development / Developer's Corner / c1c542ea4b8c (C4Aul: Add new type 'nil')

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill