PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

OOP and some other bugs

The following code with comments concerning OOP:
Code:

#class Tobj1

public proc Test1
ShowMessage("tested Tobj1");
end;

#endclass


#class Tobj2

public(
objList1$
);

list(objList1$); //List of Tobj1

public proc Test2
foreach (objList1$)
NewObject(obj$, "Tobj1", objList1$);
//it doesnt work...
//I have to use Tobj2(objList$) to make this work
obj.test1;
end;
end;

#endClass

proc TestGlobal
//Again i have to write Tobj2(GLOB$) to make this work even if this variable - global;
GLOB.Test2;
end;


proc main

#object Tobj2 o2$

for (i$, 0, 9)
#object Tobj1 o1$
Add(o2.objList1$, &o1;$);
end;


#object Tobj2 GLOB$//Global object
global(GLOB$); //We make object global variable

end;

And again (and again)(: SetSpriteDirection now in degrees, however SetSpriteAngle is in radians
The problem here is that the compiler needs to know the object class type before issuing any calls. The compiler doesn't know about variable scopes, only the interpreter. Even if the variable is defined as global, the compiler doesn't know.

Therefore you NEED to cast the variable before doing a call when the #object is defined before the call.

NewObject will only assign a pointer to an already defined class. It won't cast the variable to the class type for the compiler.

If you want to access a variable from a class, you don't need to tell the compiler what class type it is , you only need to cast when you need to call a procedure or function from within a class.

This is the new code:

Code:
#class Tobj1

public proc Test1
ShowMessage("tested Tobj1");
end;

#endclass


#class Tobj2

public(
objList1$
);

list(objList1$); //List of Tobj1

public proc Test2
foreach (objList1$)
TObj1(obj$);
NewObject(obj$, "Tobj1", objList1$);
//You need to tell the compiler what class type obj$
//is before calling it's procedure.
obj.test1;
end;
end;

#endClass

proc TestGlobal
//Same as above the compiler doesn't know the object
//class type at this point.
TObj2(GLOB$);
GLOB.Test2;
end;


proc main

#object Tobj2 o2$

for (i$, 0, 9)
#object Tobj1 o1$
Add(o2.objList1$, &o1;$);
end;


#object Tobj2 GLOB$//Global object
global(GLOB$); //We make object global variable

end;


Btw, the SetSpriteAngle() uses Degree and not Radian, I have fixed that a couple versions ago.
I dont know if I can be wrong, but even with the newest release of PPL SetSpriteAngle(2*pi*Angle$/360) where Angle$ is in degrees works correctly, otherwise not => the parameter of this function is in radians.)
Hi,

I have changed the SetSpriteAngle() back to RADIAN in the next version of PPL. I couldn't get it to work with DEGREES correctly.

You will have to convert the DEGREE value to a RAD value before calling the function from now on.

Sorry for the inconvenience.

If you can help me, i'll be gald to implement it back, here is what I am doing to convert the DEG to RAD:

double DEGREE = 360.0 / 256.0;

s->angle = angle / DEGREE;

And to convert it back from RAD to DEG:

s->angle = angle * DEGREE;

I don't know how I came up with this code but I have so much stuff on my plate that I don't want to spend too much time on this.
Rather strange way to do the convertion:).
(And I was thinking why this damned sprite turns so unpredictable:).

Here is the right way:
double CONVCONST=2*pi/360;
deg=rad/CONVCONST;
rad=deg*CONVCONST;
I always forget to login before posting topic - bad habit:)
Hi,

I had something like this bug never could get it to work right. Anyway, I will give it a try.

Thanks