UGX-Mods

Everything Else => General Discussion => Topic started by: JR-Imagine on June 14, 2016, 05:26:15 pm

Title: GSC: Object-oriented or procedural?
Post by: JR-Imagine on June 14, 2016, 05:26:15 pm
The past few months I've gotten rather familiar with the internal workings of GSC as I've been expanding CoD4's server binaries with new functionality such as input detection and HTTP POST requests etc. Now I've gotten the idea for this little discussion from someone who actually mentioned this in a shoutbox on another forum at some point and I thought it would be really interesting to see how much people actually know about the scripting language they're using on a daily basis.

So the basic question is: Is CoDScript/GSC/... (whatever you want to call it) object-oriented or procedural?

In the shoutbox discussion I saw a few very interesting answers and wanted to hear what the scripting community on UGX-Mods thinks about this subject. For the record, I'm purely doing this to spark a discussion as I'm legitimately interested to hear about people's views and I myself already know the answer to this question (if the community can't work it out I'll actually post the answer later).

For those not familiar with these terms:
Object-oriented programming (OOP): https://en.wikipedia.org/wiki/Object-oriented_programming
Procedural programming: https://en.wikipedia.org/wiki/Procedural_programming

PS: Pwn please don't spoil it, pretty sure you know the answer as you're quite familiar with the internal workings of CoD yourself. :P
Title: Re: GSC: Object-oriented or procedural?
Post by: Koan on June 14, 2016, 05:59:01 pm
(https://www.ugx-mods.com/forum/proxy.php?request=http%3A%2F%2Fimages1.wikia.nocookie.net%2F__cb20130312013034%2Frandom-ness%2Fimages%2Ff%2Ff0%2FWhy_not_both.jpg&hash=cf246cd68644d6081332afd08aaf6d87c81cea4b)

Wouldn't it simply be both? Multi-paradigm? It's object oriented in that, for example, you can refer to entities with self etc, but it's also procedural cause you can make functions that can be called at any point. Basic examples but you get the idea.
Title: Re: GSC: Object-oriented or procedural?
Post by: daedra descent on June 14, 2016, 06:22:07 pm

Assuming that the WIKI links are actually accurate:

Object Orientated, I think. Every function is an abstract interface that can accept any object(via self). No object is bound to any single function or set of functions unless the scripter specifically checks for it because "self" is abstract and isn't specific to any object type.
Title: Re: GSC: Object-oriented or procedural?
Post by: JR-Imagine on June 15, 2016, 12:03:05 pm
@Both:
The keyword "self" is actually an integer holding an entity number:
Code Snippet
Plaintext
typedef int scr_entref_t;

Behind the scenes that integer is passed onto a function through a simple argument:
Code Snippet
Plaintext
void PlayerCmd_spawn( scr_entref_t arg );

The way these functions then get the correct entity is by simply pulling it from the entity list:
Code Snippet
Plaintext
gentity_t* gentity;

if( HIWORD( arg ) ) {
Scr_ObjectError( "Not an entity" );
} else {
gentity = &g_entities[ LOWORD( arg ) ];
}

I've kinda already spoiled too much with this but whatever... :P
Title: Re: GSC: Object-oriented or procedural?
Post by: JustForFun119 on June 15, 2016, 04:27:49 pm
I'd say it is procedural because the so-call 'objects' are structures similar to C's struct.
It's just how scripting is conceptually easier to understand when we turn different game entities into some metaphors of objects.

When OOP is mentioned, some concepts such as objects, classes, inheritance, polymorphism, are expected; though it is not a part of the 'CoDScript', so I don't think it is related to OOP :)
Title: Re: GSC: Object-oriented or procedural?
Post by: jjbradman on June 16, 2016, 02:49:04 am
just asking. do procedural or object programing has anything to do with the ability to write the main function wherever you like in gsc vs lets say in c++ having to at least write the prototype of a function above the main function so you dont get compile errors? :noob_asked_be_cool: xD
Title: Re: GSC: Object-oriented or procedural?
Post by: JR-Imagine on June 16, 2016, 10:59:51 am
just asking. do procedural or object programing has anything to do with the ability to write the main function wherever you like in gsc vs lets say in c++ having to at least write the prototype of a function above the main function so you dont get compile errors? :noob_asked_be_cool: xD
It doesn't. A good example of this is both C and C++ requiring a prototype to be declared before the main function whilst C is procedural and C++ is object-oriented. ;)

Just FYI: Prototypes should be declared in header files while writing C/C++.
Title: Re: GSC: Object-oriented or procedural?
Post by: DeletedUser on June 16, 2016, 11:15:44 am
I'm not Pwn, so....
Spoiler: click to open...
it's 100% procedural
Title: Re: GSC: Object-oriented or procedural?
Post by: jjbradman on June 16, 2016, 06:19:26 pm
It doesn't. A good example of this is both C and C++ requiring a prototype to be declared before the main function whilst C is procedural and C++ is object-oriented. ;)

Just FYI: Prototypes should be declared in header files while writing C/C++.
oh  :o thanks, thats good to know xD
Title: Re: GSC: Object-oriented or procedural?
Post by: mrpeanut188 on June 23, 2016, 05:10:48 pm
Procedural. Don't have much OOP experience, but it's not hard to take one look and see it's procedural.