Author Topic: Functions in Types?  (Read 20815 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10732
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Functions in Types?
« Reply #45 on: 2010-May-05 »
Code: (glbasic) [Select]
ok%=NETWEBGET(proxy$, "http://"+webAddress$+str$, port%, baseData.tempFile$)And the C file is :
Code: (glbasic) [Select]
ok=NETWEBGET(proxy_Str, CGStr("http:");
Ah, c'mon. That's not really bad, is it? :P
Oh dear. Now you see why I made this beta. You can't imagine what type of errors I got at the first run... I'll see if I can find time to fix that soon.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5036
  • O Rly?
    • View Profile
Re: Functions in Types?
« Reply #46 on: 2010-May-05 »
OOOOOOOOOOOOOOOOOOOOOpppppps... that was to late yesterday :)
Sorry!
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10732
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Functions in Types?
« Reply #47 on: 2010-May-06 »
OK, both fixed?

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #48 on: 2010-May-06 »
Yey!  Arrays are working as is debug mode version :)

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #49 on: 2010-May-06 »
One thing that would be more efficient is that, instead of having "self" to access variables in a type, automatically assume that variable access will be done with variable from a type, and use something like "local." or "global." to access local or global variables.

Another thing :  A function defined in one type can't have the same name in another type, which is a shame...

In addition, you can't access a TYPE that hasn't already been compiled, which can be a problem if you want to pass a TYPE - you wouldn't all TYPE's in one file...

Aside from these problems, it seems to be working well, aside from the very tricky to diagnose "`__l_dbg_cont' was not declared in this scope" error.  At the moment, it seems to be caused by GLOBAL setup AS TSetup (as an example) in the main file or when a standard file is included, which is rather a problem :)
« Last Edit: 2010-May-06 by MrTAToad »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10732
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Functions in Types?
« Reply #50 on: 2010-May-07 »
can you make small code pieces for these bugs?
If you need 2 files, just paste the 2nd file below the first - will be the same internally.

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #51 on: 2010-May-07 »
The included file will generate the cont error...

[attachment deleted by admin]

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #52 on: 2010-May-07 »
With the latest beta, WHILE TRUE generates a Syntax Error on Windows XP, but not Windows 7  :blink:

Fixed now with that updated file...

It does appear the GLOBAL problem only occurs in debug mode...
« Last Edit: 2010-May-07 by MrTAToad »

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #53 on: 2010-May-07 »
There does seem to be a problem calling functions from a TYPE, for example :

Code: (glbasic) [Select]
TYPE TBorder
x%;y%;width%;height%;image%;alpha // For displaying the border

FUNCTION Initialise_Border%:setup AS TSetup
self.x%=0
self.y%=0
self.width%=setup.ReturnHalfScreenWidth()
self.height%=setup.screenHeight%
self.image%=setup.spriteLoadData[0].idNumber%
self.alpha=0.0
ENDFUNCTION

FUNCTION Render_Border%:
ALPHAMODE self.alpha
STRETCHSPRITE self.image%,self.x%,self.y%,self.width%,self.height%
ENDFUNCTION
ENDTYPE

Generates a "call to undefined function : TSetup" error, even though ReturnHalfScreenWidth is present.  However, I can access the variables in TSetup okay

A simpler example is :

Code: (glbasic) [Select]
TYPE TTest
FUNCTION moo%:
ENDFUNCTION
ENDTYPE

GLOBAL test AS TTest

test.moo()

Again, TTest (and TBorder) is in a seperate file.  It does look as though, whilst the class/type is being created, no functions are being created in it...

By the way, CODEFILE isn't quite correct :

Code: (glbasic) [Select]
#define CODEFILE_Str() (DGStr("Test.gbas.gbas"))
« Last Edit: 2010-May-07 by MrTAToad »

Offline Kuron

  • Mr. Polyvector
  • ***
  • Posts: 238
    • View Profile
Re: Functions in Types?
« Reply #54 on: 2010-May-08 »
Having fun, Gernot :D

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #55 on: 2010-May-09 »
For some reason, the following (which is all in the same main file), generates an error (error : wrong argument type : TYPE  is not declared) :

Code: (glbasic) [Select]
TYPE TFont
FUNCTION moo:
ENDFUNCTION

FUNCTION moo2:
RETURN 1
ENDFUNCTION
ENDTYPE

LOCAL font AS TFont
LOCAL big

font.moo()
big = font.moo2()

The problem seems to occur when trying to assign big to the value from moo2 - remove that, and its okay, but unfortunately, is not the desired result.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4158
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Functions in Types?
« Reply #56 on: 2010-May-09 »
I came. I saw. I played.

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #57 on: 2010-May-09 »
Pretty much agree with it - generally, OOP over-complicates things and can make this much harder to read...

However, extended types in GLBasic however, make things much easier to re-use and update.

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #58 on: 2010-May-14 »
Another slight problem found :

It appears function order matters when calling another function :

Code: (glbasic) [Select]
TYPE TImage
Width
Height

FUNCTION MidHandleImage:
self.SetHandle(self.Width/2,self.Height/2); 
ENDFUNCTION

FUNCTION SetHandle:x,y
ENDFUNCTION
ENDTYPE

This generates the usual "call to undefined function : TImage" error message.  However, if you put SetHandle before MidHandleImage :

Code: (glbasic) [Select]
TYPE TImage
Width
Height

FUNCTION SetHandle:x,y
ENDFUNCTION

FUNCTION MidHandleImage:
self.SetHandle(self.Width/2,self.Height/2); 
ENDFUNCTION
ENDTYPE

and all is fine...

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10732
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Functions in Types?
« Reply #59 on: 2010-May-17 »
Great find. I'll try to fix that one, too.