Hi Gernot
Folgendes geht nicht:
PROTOTYPE _create: mt AS TTest, text$, x%, y%
TYPE TTest
x%;y%
text$
create AS _create
ENDTYPE
GLOBAL _TTest[] AS TTest
LOCAL t AS TTest
t.create = CreateTTest
t.create(t, "test",10,20)
WHILE TRUE
PRINT t.text$, t.x, t.y
SHOWSCREEN
WEND
END
FUNCTION CreateTTest: t AS TTest, text$, x%, y%
t.x = x
t.y = y
t.text$ = text$
ENDFUNCTION
Fehlermeldung ist :
"Prototypes-test.gbas"(21) error : call to undefined function : TTest
und zeigt auf:
t.create(t, "test",10,20)
Dachte das geht...
Wie wär es mit einer zuweisung wie:
PROTOTYPE _create: mt AS TTest, text$, x%, y%
TYPE TTest
x%;y%
text$
create AS _create = CreateTTest
ENDTYPE
würde ich besser finden ...
Naja auf allefälle geht das t AS TType im PROTOTYPE nicht so wie gedacht... :'(
ähh Gernot?
Welche Fehler mit PROTOTYPE genau sind denn jetzt mit dem neuen Update beseitigt? Die bisher beschriebenen scheinbar nicht.
folgendes Coding
PROTOTYPE Init: x, y, graphic
TYPE TPlayer
x; y
graphic
ptr_init AS Init
ENDTYPE
GLOBAL player AS TPlayer
player.ptr_init = Init
player.ptr_init(100, 10, player.graphic)
// ------------------------------------------------------------- //
// --- INITPLAYER ---
// ------------------------------------------------------------- //
FUNCTION InitPlayer: px, py, pgraphic
PRINT "x:" + px + "y:" + py + "Graphic:" + pgraphic, 0, 0
ENDFUNCTION // INITPLAYER
gibt diese chice Ausgabe
C:\Users\quentin\AppData\Local\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\Users\quentin\AppData\Local\Temp\glbasic\gpc_temp0.cpp:45: error: expected primary-expression before ';' token
Dein Fehler :P
PROTOTYPE Init: x, y, graphic
TYPE TPlayer
x; y
graphic
ptr_init AS Init
ENDTYPE
GLOBAL player AS TPlayer
player.ptr_init = InitPlayer
player.ptr_init(100, 10, player.graphic)
// ------------------------------------------------------------- //
// --- INITPLAYER ---
// ------------------------------------------------------------- //
FUNCTION InitPlayer: px, py, pgraphic
PRINT "x:" + px + "y:" + py + "Graphic:" + pgraphic, 0, 0
ENDFUNCTION // INITPLAYER
Du hast eine nicht vorhandene Funktion zugewiesen.
Ausgabe war bei mir:
"_poo.gbas"(11) warning : probably unassigned variable : Init
*** Function pointer assignment seems unsafe. Please post code to forum!
sorry, mein dummer Fehler. Kaum macht man es richtig ....
Zuweisung der Funktion innerhalb der Typ-Deklaration ist aber weiterhin nicht möglich?
Bleibt das so? Wäre das überhaupt machbar?
PROTOTYPE Init: x, y, graphic
TYPE TPlayer
x; y
graphic
ptr_init AS Init = InitPlayer
ENDTYPE
GLOBAL player AS TPlayer
Das im ersten Post ist immernoch nicht möglich :(
Obwohl du sagtest, das es geht :'(
Hoppla. Muss ich nochmal schauen. Der Übergibt dem Prototype die TYPEs nicht als Referenz.
Funzt jetzt zu 100% !
Sehr geil :)
Jetzt mal so rein interessehalber
würde ein :
bla AS proty = func_point
... machbar sein?
Wär noch so das I-Tüpfelchen quasi die Sahnehaube ;)
EDIT:
Seh grad im quellcode ( Temp ) das:
class test
{
public:
DGInt id;
DGInt x;
DGInt y;
Prot_create create;
Prot_print TPrint;
test()
{
id = 0;
x = 0;
y = 0;
}
test(const test& _in_)
{*this = _in_;}
test& operator=(const test& _in_)
{
this->id = _in_.id;
this->x = _in_.x;
this->y = _in_.y;
this->create = _in_.create;
this->TPrint = _in_.TPrint;
return *this;
}
bool operator <(const test& _in_)const
{
if(this->id < _in_.id) return true;
return false;
}
bool operator >(const test& _in_)const
{
if(this->id > _in_.id) return true;
return false;
}
bool operator==(const test& _in_)const
{
return (1
&& this->id == _in_.id
&& this->x == _in_.x
&& this->y == _in_.y
&& create == _in_.create
&& TPrint == _in_.TPrint
)?true:false;
}
};
Da benutzt du ja this-> ;)
Kann man das nicht irgendwie in GLB... MOGELN :D
Dann könnte man sich auchnoch den doppelten Typeauftuf sparen:
t.create(t, 1, 200, 100)
Hier mal mein kleiner Test:
// --------------------------------- //
// Project: Prototest2
// Start: Wednesday, October 14, 2009
// IDE Version: 7.142
PROTOTYPE Prot_create: _t AS test, id, x, y
PROTOTYPE Prot_print: _t AS test
TYPE test
id
x;y
create AS Prot_create
TPrint AS Prot_print
ENDTYPE
LOCAL init AS test
init.create = Func_Create
init.TPrint = Func_Print
LOCAL t AS test
t = init
t.create(t, 1, 200, 100)
LOCAL t2 AS test
t2 = init
t2.create(t2, 2, 100, 400)
WHILE TRUE
t.TPrint(t)
t2.TPrint(t2)
SHOWSCREEN
WEND
END
FUNCTION Func_Create: t AS test, id, x, y
t.id = id
t.x = x
t.y = y
ENDFUNCTION
FUNCTION Func_Print: t AS test
PRINT t.id, t.x, t.y
ENDFUNCTION
der this Zeiger hat in GLBasic keinen Platz. Schreib ein Stück Code wo Du ihn verwendest, dann weißt Du was ich meine.
Es geht um das t.Create(t, bla, blub ... )
die doppelte übergabe ist irgendwie bescheppert :)
Ausserdem ist das zusätzliche zuweisen der Funktion irgendwie komisch
init.create = Func_Create
um dann init.create(bla, bla, bla) machen zu können.
create AS Prot_create = Func_Create
da wär eine direkte zuweisung viel schöner:
Schreibs auf wie Du's haben willst, dann siehst Du, dass es nicht geht.
Was Du willst ist:
PROTOTYPE proto_init: t AS TT
TYPE TT
init AS proto_init = MyInit( this )
ENDTYPE
Und das ist mir zu krass zum Parsen. Frag mich in einem Jahr wieder, wenn ich das vergessen habe wie ich das mit den Funktionszeigern reingefriemelt habe :D
*Lieb guck*
Aber jetzt weißt du noch wie du es gemacht hast, und bekommst es evtl doch schnell gebacken.
Frag ich dich in einem Jahr nochmal, dann musst dich erst wieder in deinen (Hast du gesagt)-> "reingefriemelten" Code zurechtfinden...
:good:
Würde dir auch ein Bier kaufen, zur Stärkung :D