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

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4154
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Functions in Types?
« Reply #30 on: 2010-May-04 »
Quote
And you won't convince me to add anything else now.

Not even DRAWOVAL/DRAWELLIPSE? ;)
I came. I saw. I played.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10726
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Functions in Types?
« Reply #31 on: 2010-May-04 »
lol. Nothing that extends the language syntax I meant.
Drawoval is no biggie. You can polyvector it yourself if you want:
Code: (glbasic) [Select]
DrawOval(100,100,99,33,RGB(255,0,0))
SHOWSCREEN
MOUSEWAIT


FUNCTION DrawOval%: x, y, w, h, col%

INC x, w/2
INC y, h/2

LOCAL phi
STARTPOLY -1, 0
POLYVECTOR x,y, 0,0,col
FOR phi = 0 TO 360 STEP 5 // how poly do you want it?
POLYVECTOR x+COS(phi)*w, y-SIN(phi)*h, 0,0,col
NEXT
ENDPOLY

ENDFUNCTION

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4154
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Functions in Types?
« Reply #32 on: 2010-May-04 »
Yeah, I know Gernot. And that was similar to a method I was using myself anyway.

It just felt like a missing command (it's been in pretty much every other extended BASIC syntax I've used for years). We have DRAWRECT as an internal command, so why not DRAWELLIPSE.

It's nothing major.
I came. I saw. I played.

Offline Kuron

  • Mr. Polyvector
  • ***
  • Posts: 238
    • View Profile
Re: Functions in Types?
« Reply #33 on: 2010-May-04 »
Most avionics packages (you know, that stuff that runs computers in the plane's front office) is programmed using OO environments (C++ or more often ADA), whether the programmer used it or not....
You seem confused, I actually love OOP.  I just do not like seeing GLB lose what makes it unique and doing something just because other languages may do it  ;)

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5034
  • O Rly?
    • View Profile
Re: Functions in Types?
« Reply #34 on: 2010-May-04 »

Code: (glbasic) [Select]
TYPE Tvec
x;y;z
FUNCTION add: b AS Tvec
   INC self.x, b.x
ENDFUNCTION
ENDTYPE

LOCAL a AS Tvec
a.add(a)


Hmmm.... work this in V8?: (Function without calling itself as parameter?)
Code: (glbasic) [Select]
TYPE Tvec
x;y;z
FUNCTION create: x, y
   self.x = x
   self.y = y   
ENDFUNCTION
ENDTYPE

LOCAL a AS Tvec
a.create(10,20)


EDIT:

Whooops... simply have to look at the first Post :P
« Last Edit: 2010-May-04 by Schranz0r »
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: 10726
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Functions in Types?
« Reply #35 on: 2010-May-04 »
For those who want to test - see the first post.

Offline Kuron

  • Mr. Polyvector
  • ***
  • Posts: 238
    • View Profile
Re: Functions in Types?
« Reply #36 on: 2010-May-04 »
Quote
Gernot is not hunting another programming environment's spec sheet.  He's  is responding to customer demand
Yes, he is and he is doing it against his better judgment. ;)

Quote
that keeps GLB from becoming a dinosaur one day...
I agree, it would be sad if GLB suffered the same fate as other indie languages that started down the OOP road.  Luckily, Gernot has put his foot down, so it is now a moot discussion and we should drop it :)   

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #37 on: 2010-May-04 »
Will you be able to get this going in debug mode too?  Works fine in release mode, but in debug mode it just generates "error: expected constructor, destructor, or type conversion before '(' token".

In addition, will this work with arrays ?  I've tried :

Code: (glbasic) [Select]
TYPE Tvec
   x;y;z
   FUNCTION null:
      self.x = 0; self.y=0; self.z=0
   ENDFUNCTION

   FUNCTION add: v AS Tvec
     INC self.x, v.x
     INC self.y, v.y
     INC self.z, v.z
     WHILE KEY(44)=0
      PRINT self.x,0,0
      SHOWSCREEN
     WEND
   ENDFUNCTION
   
   FUNCTION moo%:
   ENDFUNCTION
ENDTYPE

LOCAL push AS Tvec
LOCAL test[] AS Tvec
DIM test[0]

push.null()
DIMPUSH test[],push

test[0].moo()

But I just get : "error : call to undefined function : Tvec" with the last line.
« Last Edit: 2010-May-04 by MrTAToad »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10726
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Functions in Types?
« Reply #38 on: 2010-May-04 »
update at the beta place. Works for me now.

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #39 on: 2010-May-04 »
Same filesize and dates as the previous one - is that correct ?

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #40 on: 2010-May-04 »
I think I've found a compiler bug too - it appears that compound strings are messed up (or the compiler doesn't like //).  With the following :

Code: (glbasic) [Select]
ok%=NETWEBGET(proxy$, "http://"+webAddress$+str$, port%, baseData.tempFile$)
The compiler states :

error: expected `)' before ';' token

And the C file is :

Code: (glbasic) [Select]
ok=NETWEBGET(proxy_Str, CGStr("http:");

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5034
  • O Rly?
    • View Profile
Re: Functions in Types?
« Reply #41 on: 2010-May-04 »
 :giveup:


Code: (glbasic) [Select]
TYPE Vec
x;y;z
FUNCTION Create: x, y, z
self.x = x
self.y = y
self.z = z
ENDFUNCTION
FUNCTION Print_Debug$:
PRINT "x = "+self.x+" y = "+self.y+" z = "+self.z, 10,10
ENDFUNCTION
ENDTYPE

LOCAL v AS Vec

vec.Create(10,20,30)

"Methods.gbas"(22) error : call to undefined function : vec

Beta from first post installed...
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 bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2651
    • View Profile
Re: Functions in Types?
« Reply #42 on: 2010-May-04 »
Shouldn't that be...

Code: (glbasic) [Select]
v.Create(10,20,30)
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

MrTAToad

  • Guest
Re: Functions in Types?
« Reply #43 on: 2010-May-05 »
Yes, it should be :)

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
Re: Functions in Types?
« Reply #44 on: 2010-May-05 »
of course it should!