You can download dayz tools from steam and it has an extract game data option in it. Ofc you wont get all the data extracted but you get almost all of the scripts. Also creating small mods is pretty easy.
It's an override so chances are this isn't as bad as you think. Other subclasses may have logic but this particular item probably doesn't need it and should always be IsEat
Interesting. What languages use an override keyword for interface implementations? I know Java has the @override annotation, but that's not a first class language feature.
I can't recall if C# has a separate keyword for implementing interfaces vs overriding methods in any of the parent classes. But then I'm not sure if C# has proper interfaces anyway.
I'm pretty sure you must explicitly implement interfaces (by putting them into the parent classes list) for that to work; it doesn't work like Go where interfaces are implicitly implemented (something like C++ concepts). The override keyword is to my knowledge optional though.
I dont know what you mean with putting them into the parent classes list, but maybe our definitions of explicit and implicit vary. I go by the definitions Microsoft uses.
Trying to guess this language is iffy. It uses pascal case, which narrows it, but what boggles my mind as much as the author's reckless type coercion is this method declared as overriding another yet not having public visibility.
Then use an explicitly named datatype, because this is confusing otherwise. Or, better idea, make whatever function that uses this have the responsibility of adding the padding. You should never add implementation details from a completely unrelated class that uses this class to something like this. It defeats the entire point of interfaces.
I haven't done any C++ in ages, but IIRC the language doesn't have "true" booleans - they're integers behind the scenes. 0 is false, any other int is true. In this case, returning false would yield a 0, and true a 1.
It is C which does not have true booleans. C++ has a separate bool type which can be cast to an integer though.
I know that C++ has an actual boolean type, I was more talking how it implicitly casts, like int foo = true compiles.
Regarding they are integers behind the scenes - it is true for any programming language this way.
JavaScript (I know) doesn't have an integer type so there's an actual boolean primitive. Although the JIT probably boils that down to an integer lol. I seem to remember a couple of functional langs that don't treat booleans as integers either.
By the way, I don't think it is C++ since it does not allow the override keyword to come at the beginning of the function declaration.
I assumed C++ cause I seemed to remember that was what DayZ was developed on but now you're making me doubt haha.
I know that C++ has an actual boolean type, I was more talking how it implicitly casts, like int foo = true compiles.
Yeah, thats just weak typing for primitives.
JavaScript (I know) doesn't have an integer type so there's an actual boolean primitive. Although the JIT probably boils that down to an integer lol. I seem to remember a couple of functional langs that don't treat booleans as integers either.
I meant they all represented as integers in the RAM :)
I assumed C++ cause I seemed to remember that was what DayZ was developed on but now you're making me doubt haha.
That might be some scripting language which works on top of cpp engine. It is common for game engine today to have some scripting language which would not require you to recompile the game to test your changes
Oh, for sure. Was just trying to give an explanation as to why it was possible as a direct answer to the previous comment, cause nobody else gave the answer.
I've run into this in other games I've worked on. Often it's because it's interfacing with either a scripting language with a loose typing system, or for serialization, or even for padding.
Okay, I'll bite. How would you do this better then? You have a base item class with a function for finding out if the player can eat it and you have a subclass of that item that always can be eaten no matter the circumstance. The easiest way is to override the method and force it to be true.
Since its overriding it means that it's an instance of a class(probably a fooditem class) this particular item is always useable so it doesnt need code to check if it's eatable. Some other items might need to run check to see if they can be used and then they would run code here. Since they both come from the same class they both need to have this function
True communicates more than "1" because the function signature says "is" which is of boolean nature, so then: is the return type wrong? It could be an int because it might actually have other options like -1 for an error. In that case EatStatus would make more sense, otherwise it'd be down to this language itself not using patterns like optionals and result, which is then just unfortunate that c++ is naturally unreadable unless you're used to its odd patterns
If only a language that could still have the performance of c++, low level access, ability to still embed c++ code, and yet have these robust security and design features exist (rust).
Well, as previously mentioned in other comments this uses the override.
The purpose of this keyword is to make the function as being over-ridden when a child class inherits from it.
Suppose you had a base class of "Creature" You're never going to actually instantiate a creature. Creature is simply a framework to design other classes of similar but not the same behavior. These could be "Dude," "Big Guy," and "Gun Man."
A "Dude" IS-A creature as it inherits from "Creature." Dude can then Override the IsEat method in order to add dude specific behavior for eating.
So why does Creature need an "IsEat" method? Well, when designing a framework class you want to keep in mind your end user: Future Programmers. They have to use your class if they want their Creature in your Creatures system, so they have to know what kinds of methods creatures will use. This gives them a nice clear contract of sorts to say "You must write methods X,Y,Z to have a Creature."
So then why give the definition of the function? Well, sometimes the default behavior for a method is okay for the children to do as well. Is there ever a super practical case where the base class "IsEat" is called? Probably not, but then again I'm not a DayZ dev. (I'm not even technically a Java dev, I'm a student learning C++)
Not that this is great, but it's really the languages fault. I'm guessing it's because 1 and 0 are truthy and falsely and the language does an automatic cast. Or potentially the language doesn't support booleans at all and true and false are extensions or declared somewhere.
No way, it's the author's fault. Who names a method as a question yet declares the return type as anything but a Boolean except a twisted heathen with hate in his heart?
In this case op picked what looks like a typo from actionbase.c, in the way I think it should return bool like the others functions around it IsDrink,ect
There's probably nothing wrong with this, especially considering it's an override. Besides, is this a compiled language? If so, this function call will be compiled out entirely with basically any level of optimization so this code won't even exist in the executable.
yeah this is bad.. only noobs and inexperience coders does this specially those who doesn't know or has zero experience with OOP.. Im not referring to the posted code, im referring to OP.
32
u/chuckitoutorelse Jan 15 '23
I would love to look through the DayZ source code. Would love to try find the a few bugs that drive me nuts.
3
u/Not_a_tasty_fish Jan 16 '23
It should be required that OPs in this sub have to state why they think the code is bad.
530
u/[deleted] Jan 15 '23
It's an override so chances are this isn't as bad as you think. Other subclasses may have logic but this particular item probably doesn't need it and should always be IsEat
221
u/Lataero Jan 15 '23
This is absolutely not bad. It's an override. This is purposely there to avoid the base logic for this particular implementation.
65
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 15 '23
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
49
u/SanianCreations Jan 15 '23
Dorito is eat
Club penguin is kill
23
u/[deleted] Jan 15 '23
There are many legitimate reasons why this might exist
22
u/[deleted] Jan 15 '23
You obviously don't know OOP
11
u/[deleted] Jan 15 '23
This can only exist because of inheritance
5
u/[deleted] Jan 15 '23
Question: how is a function that is supposed to return an int returning a Boolean data type?
3
u/TheHeksiiii Jan 15 '23
valid
3
u/kappcity Jan 15 '23
Not bad code. This is oop π€·ββοΈ
3
u/ssjskipp Jan 15 '23
So what? He be eatin'
3
u/[deleted] Jan 16 '23
The only crime here is the name of that function
5
u/Tsalikon Jan 15 '23
Not that this is great, but it's really the languages fault. I'm guessing it's because 1 and 0 are truthy and falsely and the language does an automatic cast. Or potentially the language doesn't support booleans at all and true and false are extensions or declared somewhere.
2
u/Icepenguins101 Jan 16 '23
I would remove this code as soon as possible if i was part of the DayZ team, as I usually keep mine steady.
2
u/micro-amnesia Jan 16 '23
I called the cops on this
2
u/cooltrain7 Jan 16 '23
Little bit of info for some. Dayz SA uses its own scripting lanaguage that is similar in syntax to C#.
You can view the source here.
In this case op picked what looks like a typo from actionbase.c, in the way I think it should return bool like the others functions around it
IsDrink,ect2
u/cnfnbcnunited Jan 24 '23
Everyone speaking about the logic, but I can't stand it being called "IsEat"...
1
u/[deleted] Jan 16 '23
how the hell do you even have access to this?
1
u/vo9do9 Jan 16 '23
that's just OOP garbanzo
1
u/jjman72 Jan 16 '23
Because this is an override, this isnβt bad at all.
1
u/[deleted] Feb 08 '23
There's probably nothing wrong with this, especially considering it's an override. Besides, is this a compiled language? If so, this function call will be compiled out entirely with basically any level of optimization so this code won't even exist in the executable.
1
u/KeithTheBirb Jan 16 '23
r/comedyheaven
1
u/praningdev Jan 16 '23
yeah this is bad.. only noobs and inexperience coders does this specially those who doesn't know or has zero experience with OOP..
Im not referring to the posted code, im referring to OP.
1
u/[deleted] Jan 16 '23
There is nothing wrong here. Perhaps you should sharpen your skills before you take a dig at others.
-1
u/[deleted] Jan 15 '23
If(true) ..... return true π