Mystic Software Forums
Mystic Software => General Discussion => Topic started by: AlienDude on April 14, 2005, 02:57:54 PM
-
I ws tryin out the oop for classes and this is what i have for player stats (this is just a snippet btw):
sikhil = new(player)
kis!=sikhil->gethmax()
mwin("<kis!>")
wait()
windows()
class player
{
private:
handle$
maxhp!
hp!
maxsp!
sp!
str!
def!
dex!
int!
wis!
agi!
status[]! //status effects affecting players
eq[6]$ //equip slots
public:
method player()
method ~player()
method gethmax() {return this->maxhp!}
method getsmax() {return this->maxsp!}
method gethp() {return hp!}
method sethp(x!)
method sethp(dir$)
method getstat(stat$)
method seapp(se!)
method sedel(se!)
method equip(slot!, item$)
method unequip(slot!, item$)
method levelup()
}
method player::player()
{
str!=16
def!=16
dex!=16
int!=16
wis!=16
agi!=16
maxhp!=46
hp!=46
maxsp!=34
sp!=34
}
method player::~player() {}
method player::player(pstat!)
{
str!=pstat!
def!=pstat!
dex!=pstat!
int!=pstat!
wis!=pstat!
agi!=pstat!
}
method player::gethmax() {return this->maxhp!}
method player::getsmax() {return this->maxsp!}
[snip]
the gethmax() call came up "0" wtf is wrong,
oh all the methods are defined in the program
doyou have to have the public part before the private part, which is weird, why now just use teh same form as in c++?
-
Use Return(maxhp!) the this-> is automatically implied
-
Use <a href='http://tk3.toolkitzone.com/help/?page=19#returnmethod' target='_blank'>returnMethod()</a>. <a href='http://tk3.toolkitzone.com/help/?page=19#return' target='_blank'>return()</a> is an old TK2 function.
Pretty pointless class too.
-
As I said before it is a snippet, so all the "non-pointless" isn't on there. :angry:
And was teh syntax right from what I showed u?
You wrote the damn commands
How bout the private/public order? Why cant it be the same as C++?
-
What are you mumbling about public are private? You can indeed intermingle parts of both. Try it.
For clarification, private is C++'s protected, not its private.
-
i was worried about the order because it's the opposite frommwhat imlearning so i thought it was required syntax.
thanx for the clarifcation
a little bit related question: is pointer arithmetic possible in RPGCode? it may help smth im doing. also again, why did it return 0 and not 46
-
Ersuis already gave you a great answer to your pointer question. Go fetch it. In summary: pointers are evil. All modern langauges are abolishing them; RPGCode does not need them, and it will never have them.
As for 'order', I recomend you put the public visibility first. Implementation over interface is archaic.
-
I'm surprised, Colin. That's sort of a newbie-ish programmer's remark. (Heh...) Pointers are far from evil. I couldn't imagine doing much of anything practical in C without them. And, yes, pointers could be quite useful in RPG Code (though probably not neccessary).
(By the way, started playing with TK3. I'm quite impressed! I'll post a commentary/bug-report over at TKZ soon.)
-
I think you misunderstood me; pointers are very useful for lots of things. We use them in trans3 excessively for blits and the like! But they're being removed from many higher level (C is high level too, but not as high; hence the usage there) languages because they are dangerous and not type safe. (I generally use evil to mean 'not type safe'.) It depends on what type of language you're using, Xorlak. In the context of RPGCode, pointers would indeed by evil; there's no reason to access memory directly in a language for creating RPG games!
Only C diehards defend pointers Wink. C++ even shows that pointers are becoming less liked by providing safer references, and encouraging the use of the STL's classes like 'string' as opposed to pointers to char arrays for strings. I guess the folks at ISO and ANSI are a bunch of newbs, heh.
-
i KNOW the danger the possibility of incorrect pointers are!!!!!
and i was just seeing if it was POSSIBLE!!!!! NOT EVIL OR GOOD OR TYPE SAFE!!!
it is faster that standard array indexing itested myself!!!
and again, when i am very fluent in the language and maybe a couple of others, i will be helping out. In fact im getting the 0.6 source on monday so i can help out and examine this masterpiece.
another question: is canvassing fully inplemented now or do you have to use plugins for it to have access to all the canvassing commands? there are no blitting commands unless they're cloaked in other commands. You even said before yourself that they weren't.
but i do have to say this, despite all this you guys did a stellar job on 3.0.6!!! i wanted to make that clear. Smile two thumbs up!!!
-
int x[1];
x[0] = 5; // A
*x = 5; // B
Which is faster: A or B? Oh wait, they're both the same! You know why? In C, the subscript operator just does *(arr + index). Pointers are useful, but not as a replacement for array indexing.
-
ok i thought it hade to seach memory the amount of times equal to the number of dimensions while pointer arithmetic is just that, a couple quick calculations to find what u were looking for. so all ive read WAS wrong huh? hmmmm...
my arrays were to be at lest two dimensions
-
Here's some nice proof:
int x[1];
int y = 0;
y[x] = 5; // Sets x[0] to 5.
There's no magic at work.
Two dimensions are again not magical.
x[0][0] = 5;
Will become: *((*(x + 0)) + 0). Then your compiler will probably simplify it to **x.
-
i know that single dmension arrays are the same thing
single dimension arrays work the same way as pointer arithmetic as there are no other dimensions to calculate sizeof() u are just adding the offset of the last dimension just like single dimemsoin array indexing.
-
Wow, you really have no clue.
int *x = (int *)malloc(sizeof(int) * 2);
*x = 1; // x[0] = 1
*(x + 1) = 2; // x[1] = 2
free(x);
Ints are the size of the system word (32-bits on Win32). I only incremented the pointer by 1, so how did I set the second int? Let me tell you how: pointer maths is all based on the size of the pointer type.
-
a clue i have...the right ones, that may be another story...i may have gotten it wrong im me head, no need to get in a tiff about it.
no magic anywhere but in ourselves!!!
to reiterate, is canvassing fully implemented now?
-
Great way to escape.
Blit functions do exist (and always have).
- <a href='http://tk3.toolkitzone.com/help/?page=19#drawcanvas' target='_blank'>drawCanvas()</a></li>
- <a href='http://tk3.toolkitzone.com/help/?page=19#drawcanvastransparent' target='_blank'>drawCanvasTransparent()</a></li>
-
i didn't escape you answered teh question...
yeah but do they delete the previously made images
either i messed up with the syntax or smth weird happened but the picture showed up twice, not once in a diifferent position...this was for the damn cursor menu i put on hold
my apologies for the typos, damn my 10 thumbs Smile
EDIt i DID use killcanvas per frame btw
-
What do you mean, delete the previously made images?
-
Maybe he just doesn't understand how to backbuffer.
<a href='http://toolkitzone.com/library.php?mode=read&doc=173' target='_blank'>http://toolkitzone.com/library.php?mode=read&doc=173</a>
-
i must have screwed up the killcanvas command or smth... any input colin?
-
Hold on, what the feck are you trying to do? You've strayed far from your original question...
-
I think he just needs to read that article. Here's another link for additional emphasis:
<a href='http://toolkitzone.com/library.php?mode=read&doc=173' target='_blank'>http://toolkitzone.com/library.php?mode=read&doc=173</a>
-
Heh, I'm re-reading that one now, actually. Might help with my rain issues... Feck, I might as well read your entire series while I'm at it. Hm...
-
reread u mean, so i have ot copy those classes into a prg for all this to work, ok, ill get crackin then and lill update soon. I thought there were commands built in that did the things u discussed on there. woops.
-
The classes were just to talk about conceptual use. What you need to do, my friend, is read.
You also need to learn that killCanvas() frees a canvas; it does not clear it. Use clear(cnv!) to clear a canvas.
-
Thanks i DID do smth wrong, that's what i was asking. cant wait what 0.7 brings!! Oh wait i will be well versed by then!! so none of this crap will happen again.
sorry i had to use a bit of anger to get it out.
-
I think you misunderstood me; pointers are very useful for lots of things. We use them in trans3 excessively for blits and the like! But they're being removed from many higher level (C is high level too, but not as high; hence the usage there) languages because they are dangerous and not type safe. (I generally use evil to mean 'not type safe'.) It depends on what type of language you're using, Xorlak. In the context of RPGCode, pointers would indeed by evil; there's no reason to access memory directly in a language for creating RPG games!
Only C diehards defend pointers Wink. C++ even shows that pointers are becoming less liked by providing safer references, and encouraging the use of the STL's classes like 'string' as opposed to pointers to char arrays for strings. I guess the folks at ISO and ANSI are a bunch of newbs, heh.
Good. You scared me for a second. Yeah, I would be more of a C fan than a C++ fan (heh...)