Functions in Types?

Previous topic - Next topic

Ian Price

QuoteAnd you won't convince me to add anything else now.

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

Kitty Hello

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


Ian Price

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.

Kuron

Quote from: Ocean on 2010-May-04Most 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  ;)

Schranz0r

#34
Quote from: Kitty Hello on 2010-May-03

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
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

For those who want to test - see the first post.

Kuron

QuoteGernot 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. ;)

Quotethat 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

#37
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.

Kitty Hello

update at the beta place. Works for me now.

MrTAToad

Same filesize and dates as the previous one - is that correct ?

MrTAToad

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:");

Schranz0r

 :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 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

bigsofty

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

Yes, it should be :)

Quentin

of course it should!