Project X Forums http://px.worms2d.info/forum/ |
|
Scripting: ADTs and generic classes in EAX. http://px.worms2d.info/forum/viewtopic.php?f=15&t=665 |
Page 1 of 1 |
Author: | Danylo [ Tue Aug 13, 2013 8:24 pm ] | ||
Post subject: | Scripting: ADTs and generic classes in EAX. | ||
Hello! In this topic Im going to talk about abstract data types and generic classes in EAX. I couldn't find any information about ADTs in EAX, so I decided to make my own script which allows creation of ADTs. I have succeed in creating of an queue of integers, but... as usual programmer does, I must make a generic class (template in C++)! I've found that script editor highlights the word template as a keyword. But I have no idea how to make it here, although the creation of template class in C++ is not a big deal for me. Also, editor highlights such words as class, struct, const, and many others, but they don't behave in the way they behave in C++. (Don't even try to use const keyword! It causes some scary access violation messages :O !) So my question is: Is it possible to make a generic class in EAX? There is a step-by-step creation of very primitive queue of integers below: 1. Creation of the Node class: Code: //----------------------------------------------------------------------------- CIntNode : CObject; //----------------------------------------------------------------------------- CIntNode::CIntNode(CObject* Parent) { super(Parent, GS); Data = 0; } //----------------------------------------------------------------------------- void CIntNode::NewNext(int data) { Next = new CIntNode(this); Next->Data = data; Next->Next = NullObj; Next->Prev = this; } //----------------------------------------------------------------------------- void CIntNode::NewPrev(int data) { Prev = new CIntNode(this); Prev->Data = data; Prev->Next = this; Prev->Prev = NullObj; } //----------------------------------------------------------------------------- 2. Creation of Queue class: Code: //----------------------------------------------------------------------------- CIntQueue : CObject; //----------------------------------------------------------------------------- CIntQueue::CIntQueue(CObject* Parent) { super(Parent, GS); // Make the first node: Head = new CIntNode(Parent); Tail = Head; } //----------------------------------------------------------------------------- void CIntQueue::Push(int data) { Tail->NewNext(data); Tail = Tail->Next; } //----------------------------------------------------------------------------- int CIntQueue::Pop() { local retInt = Head->Data; // local destroyingHead = Head; Head = Head->Next; //comment: Why does it crashes the game??? I do not need to free the memory??? O_O //delete destroyingHead; return retInt; } //----------------------------------------------------------------------------- 3. Testing: I have already written the debug interface script based on tuturial on PX Wiki with some enchantments: there is a global string array variable debugStrs in wich I can place data wich is displayed on a screen in the game. So: Code: //----------------------------------------------------------------------------- require d_debug_interface; //----------------------------------------------------------------------------- int debugStrsIndex; //----------------------------------------------------------------------------- void int_queue_test::FirstFrame() { debugStrsIndex = 0; CIntQueue* IntQueue = new CIntQueue(Root); IntQueue->Push(123); IntQueue->Push(4); IntQueue->Push(5); // "stupid" access of data debugStrs[debugStrsIndex++] = "IntQueue->Head->Data:"; debugStrs[debugStrsIndex++] = ItoA(IntQueue->Head->Data); debugStrs[debugStrsIndex++] = "IntQueue->Head->Next->Data:"; debugStrs[debugStrsIndex++] = ItoA(IntQueue->Head->Next->Data); debugStrs[debugStrsIndex++] = "IntQueue->Head->Next->Next->Data:"; debugStrs[debugStrsIndex++] = ItoA(IntQueue->Head->Next->Next->Data); debugStrs[debugStrsIndex++] = "IntQueue->Head->Next->Next->Next->Data:"; debugStrs[debugStrsIndex++] = ItoA(IntQueue->Head->Next->Next->Next->Data); // the data access as it supposed to be debugStrs[debugStrsIndex++] = "Popping:"; debugStrs[debugStrsIndex++] = ItoA(IntQueue->Pop()); debugStrs[debugStrsIndex++] = ItoA(IntQueue->Pop()); debugStrs[debugStrsIndex++] = ItoA(IntQueue->Pop()); debugStrs[debugStrsIndex++] = ItoA(IntQueue->Pop()); } //----------------------------------------------------------------------------- 4. I load the game and see the output (image in the attachment). If you, guys, know how to make the template class, you can show it on this example above or as you wish. Thanks in advance.
|
Author: | PyroMan [ Sat Aug 31, 2013 7:45 pm ] |
Post subject: | Re: Scripting: ADTs and generic classes in EAX. |
What i can say according to my experience, is that LibEditor highlights some C++ keywords, but it doesnt means that they are part of EAX script. Probably Entuser just used C++ based "highliter" and implemented into LibEditor. I would do the same on his place - becouse thats easiest and fastest way. I`ve read about ADT on link that you provided and about generic classes. I`ve been learning how utils.pxl works and other libs. And i think that kind of thing that you looking for. Also i found interesting is about using parameters. i have some animation params in spritebuilder lib, that could be updated, changed, added etc independently and without any need to update libs that use them. I see that you have made CIntNode as CObject. But i think this is absolutely unnecessary for general classes. Just write void ClassName::Function(type params) //no class declaration required earlier. it just dont need, since it will be proceeded only by calling from other functions. { // anything here // return blah_blah } and so on. Once you lib/scheme has it in require/attached, those functions/variables could be written in that lib and executed without any problems. U can call them whenever you like and proceed. Also those function will be listed in LibEditor inside script aditor on top right corner in functions list as available function. Well, i hope this will help you at leassta bit. I have to warn also, that im not super programmer out of EAX. I just learned EAX by learning how existing scripts works. So dont be surprise if my answer could be obvious for you. Becouse as i noticed, you have some programming experience out of worms. |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |