GLBasic forum

Main forum => FAQ => Topic started by: johngood on 2009-Aug-31

Title: Blitz Basic to GLBasic
Post by: johngood on 2009-Aug-31
I am trying to convert a Blitz Basic game for GLBasic

Blitz Basic      GLBasic

Type Boss1      TYPE Boss1
   Field X          X
   Field Y          Y
   Field S          S
   Field L          L
   Field D          D
   Field F          F
End Type         ENDTYPE

That part was easy but this part?

For h.Boss1 = Each Boss1
   Delete h
Next

Tried this but does not work!

LOCAL h[] AS Boss1
FOREACH h IN Boss1
   DELETE h
NEXT

Any help would be great thanks.

johngood.
Title: Re: Blitz Basic to GLBasic
Post by: Schranz0r on 2009-Aug-31
here we go:

Code (glbasic) Select
TYPE TBoss1
X
Y
S
L
D
F
ENDTYPE

// set this global if you want to use it in a function!
GLOBAL _TBoss1[] AS TBoss1


// create some bosses
FOR i = 0 TO 9
LOCAL b AS TBoss1

b.X = i*20
b.Y = 10
b.S = i

DIMPUSH _TBoss1[], b // set this boss in the "bossarray"!
NEXT







WHILE TRUE

// Show all bosses
FOREACH b IN _TBoss1[]
PRINT b.S, b.X, b.Y
NEXT

// if SPACE-Key hit then delete all bosses!
IF KEY(57)
FOREACH b IN _TBoss1[]
DELETE b
NEXT
ENDIF

SHOWSCREEN
WEND
END
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Aug-31

Thanks Schranz0r for a quick and very helpfull reply.  :good:

As usual the people on this site are always very helpfull, its not surprising
that more and more prople are choosing GLBasic as their Programming language.


Thanks again.
Best Regards
johngood.
Title: Re: Blitz Basic to GLBasic
Post by: PeeJay on 2009-Aug-31
There is an even easier way of deleting all entries of a type - using the above example, simply doing
Code (glbasic) Select
DIM _TBoss1[0]
will save all that messing about with the FOR...NEXT loop
Title: Re: Blitz Basic to GLBasic
Post by: Kitty Hello on 2009-Sep-01
and REDIM _TBoss1[0] will do the same thing as DIM _TBoss1[0], except it will not free the memory, thus allowing you to use the memory for new allocations much faster. (Use that for bullets, e.g.)
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Sep-01
Hi its me again, oh NO I hear you say: :S

Thanks to PeeJay and Kitty Hello for additional input. :good:

The first game I wanted to convert was Galax2.bb it was
quite large so I settled for SpaceInvaders.bb which is
the code below, never having used Blitz Basic my only
reason for choosing it was that you seem to have users
who have used it and also use GLBasic.


Blitz Basic                                                                      GLBasic

Global player.playerdata                = New playerdata      >   ? Lost
Global bullet.bulletdata                 = New bulletdata        >   ? Lost
Global alienbullet.alienbulletdata     = New alienbulletdata  >   ? Lost

; Game types
Type playerdata
  Field x
  Field y
  Field speed
End Type

Type bulletdata
  Field x
  Field y
  Field speed
  Field state
End Type

Type aliendata
  Field x
  Field y
  Field image
  Field state 
End Type

Type alienbulletdata
  Field x
  Field y
End Type

As you can see their is no TYPE declaration
for player or bullet other that below?

; Define variables                                                  ;Define variables
player\x     = 10                    >                              player.x   = 10
player\y     = 420                  >                              player.y   = 420
player\speed = 2                   >                              player.speed  = 2
bullet\speed = 8                    >                              bullet.speed  = 8
                                                                         Error: TYPE is not declared
this is used later in the code                                   even if I declare it!
                                                                         so this will not compile

DrawImage playerbullet, bullet\x, bullet\y       >          DRAWSPRITE 0, bullet.x, bullet.y             
DrawImage playership, player\x, player\y       >           DRAWSPRITE 1, player.x, player.y

Do any of you have a lookup sheet of Blitz Statements and GLBasic equivalents?

Regards
johngood.
Title: Re: Blitz Basic to GLBasic
Post by: Ian Price on 2009-Sep-01
Here's a simple way of displaying Type data

Code (glbasic) Select


SETSCREEN 640,480,0

// Player Type data
TYPE Tplayer
 x=100
 y=100
 speed=50
ENDTYPE

// Set the variable player to get data from the Tplayer Type
LOCAL player AS Tplayer

// Main loop

// Repeat until ESC pressed
WHILE TRUE

// Show Type data on screen
PRINT player.x+" "+player.y+" "+player.speed,10,10

SHOWSCREEN

// End loop when condition met (ESC pressed)
WEND


All that will do is take your data set up in the TYPE statement and show it to you. You can change the LOCAL variable name to whatever you want, but it'll still get the Type data for the Tplayer Type. You can update the TYPE data by simply using something like this in the main loop -
Code (glbasic) Select

IF KEY(205) THEN INC player.x, 2

to move the player position right by 2 pixels when pressing the RIGHT cursor. :)

One thing to remember is that GLBasic is case sensitive, so be careful when defining your variables etc.
Title: Re: Blitz Basic to GLBasic
Post by: PeeJay on 2009-Sep-01
Hiya John

You might find it useful to have a quick look on my site - there are tutorials on there - you may find the Highway tutorial very useful, especially bearing in mind I wrote that shortly after switching from Blitz to GL myself.

Unfortunately, there isn't a direct translation type lookup table, as there are some things that there is no direct equivalent for (eg Blitz has TILEBLOCK, with no equivalent in GL ..... I miss that! GL has POLYVECTOR, with no equivalent in BB)

Hope that helps ....
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Sep-02
Thanks PeeJay at this very moment I am going through your Highway tutorial. =D

Nice job and well documented, I dont know if you still have the original Blitz code as it would
be good to see just how the Blitz code was converted to your GLBasic code!

Regards
Johngood.

Title: Re: Blitz Basic to GLBasic
Post by: PeeJay on 2009-Sep-02
Check your inbox  :x
Title: Re: Blitz Basic to GLBasic
Post by: Kitty Hello on 2009-Sep-02
TILEBLOCK is not LOADANIM?
Title: Re: Blitz Basic to GLBasic
Post by: Ian Price on 2009-Sep-02
QuoteTILEBLOCK is not LOADANIM?
Nope - totally separate commands.

Quote
TileBlock

Similar to TileImage but ignores transparency. Use this to tile an entire or portion of the screen with a single repetative image.

Blitx code -
Code (glbasic) Select

; TileBlock example
Graphics 800,600,16

; Load an image to tile (your location might vary)
gfxBall=LoadImage("C:Program FilesBlitz Basicsamplesall.bmp")

; Tile the graphic without transparency
TileBlock gfxBall

; Wait for ESC to hit
While Not KeyHit(1)
Wend

Title: Re: Blitz Basic to GLBasic
Post by: Kitty Hello on 2009-Sep-03
is that of any use?
Title: Re: Blitz Basic to GLBasic
Post by: PeeJay on 2009-Sep-03
Extremely useful, yes, for repetitive tiled backgrounds, but also for parallax scrolls (as it fills the viewport, and the offset can be used for the scroll effect)

This is taken from the BB helpfile (as Ian explained, TileImage / TileBlock are basically the same command, just with the latter ignoring transparency)


Code (glbasic) Select
TileImage handle,[x],[y],[frames]
Definition
Tiles the screen with an image (or its frames) of your choice. 

Parameters
handle= variable holding the image's handle
x=starting x location of the tile; assumed 0
y=starting y location of the tile; assumed 0
frames=the frame of the image to tile; optional with imagestrip 

Description
If you want to make a starfield or other easy tiled background, this is YOUR command. All you have to do is specify the image handle (an image loaded with the LoadImage or LoadAnimImage command). Optionally, you can specify a starting x and y location, as well as an optional frame. You can milk some serious parallax effects with a simple imagestrip with a couple of various starfields and the TileImage command. 

Example
; CreateImage/TileImage/ImageBuffer example

; Again, we'll use globals even tho we don't need them here
; One variable for the graphic we'll create, one for a timer
Global gfxStarfield, tmrScreen

; Declare graphic mode
Graphics 640,480,16

; Create a blank image that is 320 pixels wide and 32 high with 10 frames of 32x32
gfxStarfield=CreateImage(32,32,10)

; loop through each frame of the graphic we just made
For t = 0 To 9
; Set the drawing buffer to the graphic frame so we can write on it
SetBuffer ImageBuffer(gfxStarfield,t)
; put 50 stars in the frame at random locations
For y = 1 To 50
Plot Rnd(32),Rnd(32)
Next
Next

; Double buffer mode for smooth screen drawing
SetBuffer BackBuffer()

; Loop until ESC is pressed
While Not KeyHit(1)

; Only update the screen every 300 milliseconds. Change 300 for faster or
; slower screen updates
If MilliSecs() > tmrScreen+300 Then
Cls ; clear the screen

; Tile the screen with a random frame from our new graphic starting at
; x=0 and y=0 location.
TileImage gfxStarfield,0,0,Rnd(9)
Flip ; Flip the screen into view
tmrScreen=MilliSecs() ; reset the time
End If
Wend


You thinking of adding it then, Gernot?  =D
Title: Re: Blitz Basic to GLBasic
Post by: Ian Price on 2009-Sep-03
I requested this over a year ago, so YES!
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Sep-03

Sorry PeeJay there is nothing in my inbox here!  :O

Regards
johngood.
Title: Re: Blitz Basic to GLBasic
Post by: Kitty Hello on 2009-Sep-04
Do I understand that command correctly?

It's does a "loop" to tile the specified sprite all over the screen, with a given offset?

Like:
Code (glbasic) Select

x  =xstart
WHILE x < screenwidth
   y = ystart
   while y< screenheight
      DRAWANIM id, frame, x,y
      INC x, tileheight
    wend
    inc y, tilewidth
wend
Title: Re: Blitz Basic to GLBasic
Post by: Ian Price on 2009-Sep-04
Yes, the above Blitz tile commands cover the whole screen - if a tile goes off any side it returns on the opposite side, so there are never any gaps. One of the Blitz commands does not include masking, the other does.

Another tile command (I remember especially from PlayBasic) repeats a specified tile across a given area - not necessarily the whole screen eg it could just put a repeating tilestrip across the bottom of the screen that loops left to right. etc.

Both are easy to replicate in code/functions however, as you have demonstrated above and as I did in B'lox!
Title: Re: Blitz Basic to GLBasic
Post by: Kitty Hello on 2009-Sep-05
I see. I added it to my todo list. It's not hard to do and might be slightly faster when you draw the lot in one batch.
Title: Re: Blitz Basic to GLBasic
Post by: codegit on 2009-Sep-05
Agree. This is a valuable command to have. I used it alot with BlitzBasic. I have replicated my own version, but if it can be coded internally and run faster, that will be good news.  :good:
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Oct-01
Hi Guys its me again   ;/

Still can't get my head around converting BlitzBasic programs, I think I am
just too old now or very thick...

I have dropped my sites to a very small conversion of Spider.bb

What does this statement do as it is never used in the program and it generates an Error in GLBasic?

Global Enemy.SpiderData

How would the following be written in GLBasic

Enemy = New SpiderData  //  in Function InitEnemy()  I have tried LOCAL Enemy AS SpiderData followed by DIMPUSH spiderdata[], Enemy


For Enemy = Each SpiderData   // in Function DrawEnemies() I have tried FOREACH Enemy IN  SpiderData generates wrong argument type


Any further help would be great thanks.

Regards,
johngood.


Code (glbasic) Select

Global Enemy.SpiderData


Function InitEnemy()
Enemy                   = New SpiderData
Enemy\xpos              = Rnd(32,620)
Enemy\ypos              = Enemy_Ypos_Start
Enemy\speed             = 1
Enemy\animframe         = 0
Enemy\animcount         = 1
Enemy\animpause         = 4
Enemy\hit               = False
End Function


Function DrawEnemies()
For Enemy = Each SpiderData
DrawImage spiders,Enemy\xpos,Enemy\ypos,Enemy\animframe
Enemy\animcount = Enemy\animcount + 1
If Enemy\animcount > Enemy_Anim_Pause Then
Enemy\animcount = 1
If Enemy\hit = False Then
Enemy\animframe = 1 - Enemy\animframe
Else
Enemy\animframe = Enemy\animframe + 1
If Enemy\animframe >7 Then
Delete Enemy
EndIf
EndIf
EndIf
If Enemy <> Null Then
Enemy\ypos = Enemy\ypos - Enemy\speed
If Enemy\ypos <15 Then
GameOver = True
Delete Each SpiderData
EndIf
EndIf
Next
End Function

Title: Re: Blitz Basic to GLBasic
Post by: MrTAToad on 2009-Oct-01
QuoteGlobal Enemy.SpiderData
Would be something like :

TYPE SpiderData
ENDTYPE

GLOBAL enemy[] as SpiderData

QuoteEnemy = New SpiderData  //  in Function InitEnemy()  I have tried LOCAL Enemy AS SpiderData followed by DIMPUSH spiderdata[], Enemy
Technically, its not needed.  What you do is just define a type and then put data in it and then use DIMPUSH to put the type in the array.  For example :

FUNCTION add:
local dummy as SpiderData

// Put stuff in dummy
DIMPUSH enemy[],dummy
ENDFUNCTION

QuoteFor Enemy = Each SpiderData   // in Function DrawEnemies() I have tried FOREACH Enemy IN  SpiderData generates wrong argument type
FOREACH enemy in enemy[]
NEXT

All \ are placed by .

There is no NULL is GLBasic, so that part isn't needed really
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Oct-01
Thanks for your quick response MrTAToad  =D

With your help I have the following:

LOADANIM "gfx/spider_shapes.bmp",1,16,16

TYPE SpiderData
   xpos
   ypos
   animframe
   animcount
   animpause
   speed
   hit
ENDTYPE

GLOBAL spiderdata[] AS spiderdata

GLOBAL Enemy[] AS SpiderData

bla bla

FUNCTION InitEnemy:
   LOCAL dummy AS SpiderData   
   dummy.xpos              = RND(100)
   dummy.ypos              = Enemy_Ypos_Start
   dummy.speed             = 1
   dummy.animframe         = 0
   dummy.animcount         = 1
   dummy.animpause         = 4
   dummy.hit               = FALSE
   DIMPUSH Enemy[], dummy
ENDFUNCTION

FUNCTION DrawEnemies:
   FOREACH Enemy IN  Enemy[]
      DRAWANIM 1,Enemy.animframe,Enemy.xpos,Enemy.ypos
      Enemy.animcount = Enemy.animcount + 1   
      IF Enemy.animcount > Enemy_Anim_Pause
         Enemy.animcount = 1
         IF Enemy.hit = FALSE
            Enemy.animframe = 1 - Enemy.animframe
         ELSE
            Enemy.animframe = Enemy.animframe + 1
            IF Enemy.animframe >7
               DELETE Enemy
            ENDIF//Enemy.animframe
         ENDIF
      ENDIF
      IF Enemy
         Enemy.ypos = Enemy.ypos - Enemy.speed
         IF Enemy.ypos <15
            GameOver = TRUE
            DELETE Enemy
         ENDIF
      ENDIF
   NEXT
ENDFUNCTION

This is what the compiler produces!    :'(

Regards,
johngood.


Code (glbasic) Select

In file included from C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:2:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: `spiderdata' was not declared in this scope
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: template argument 1 is invalid
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: ISO C++ forbids declaration of `spiderdata' with no type
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:6: error: type/value mismatch at argument 1 in template parameter list for`template<class T> class __GLBASIC__::DGArray'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:6: error:   expected a type, got `__GLBASIC__::spiderdata'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:6: error: invalid type in declaration before ';' token
In file included from C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:1:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: `spiderdata' was not declared in this scope
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: template argument 1 is invalid
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: ISO C++ forbids declaration of `spiderdata' with no type
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::DrawEnemies()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:242: error: no match for call to `(__GLBASIC__::SpiderData) (int)'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:268: error: no matching function for call to `DIMDEL(__GLBASIC__::SpiderData&, int&)'
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:788: note: candidates are: void __GLBASIC__::DIMDEL(__GLBASIC__::DGIntArray&, int)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:798: note:                 void __GLBASIC__::DIMDEL(__GLBASIC__::DGNatArray&, int)
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:279: error: could not convert `Enemy' to `bool'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::CheckCollision()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:313: error: no match for call to `(__GLBASIC__::SpiderData) (int)'
*** FATAL ERROR - Please post this output in the forum
Title: Re: Blitz Basic to GLBasic
Post by: MrTAToad on 2009-Oct-01
Quoteerror: `spiderdata' was not declared in this scope
Variables are case-sensitive.  You define the TYPE as
Code (glbasic) Select
TYPE SpiderDatabut try and use it as
Code (glbasic) Select
GLOBAL spiderdata[] AS spiderdata
Title: Re: Blitz Basic to GLBasic
Post by: codegit on 2009-Oct-02
This was one of the first things that caught me as well when I moved from Blitz. Try remmember that GLBASIC is case sensitive.  =D
Title: Re: Blitz Basic to GLBasic
Post by: Ian Price on 2009-Oct-02
Quote from: codegit on 2009-Oct-02
Try remmember that GLBASIC is case sensitive.  =D

That'll be GLBasic then :P
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Oct-02
Sorry guys I keep forgetting how case sensitive GLBasic is, it does no have a Case switch! :whistle:

I have been commenting all the routines out and debugging them one at a time.
I am learning a lot from you guys thanks. :good:

I am stuck at the FUNCTION DrawEnemies.

I have not called DrawEnemies in the code but I have un-commented the Function and it generates
the Errors below

FUNCTION DrawEnemies:
   FOREACH Enemy IN  Enemy[]
      DRAWANIM 8,Enemy.animframe,Enemy.xpos,Enemy.ypos
      Enemy.animcount = Enemy.animcount + 1
      IF Enemy.animcount > Enemy_Anim_Pause
         Enemy.animcount = 1
         IF Enemy.hit = FALSE
            Enemy.animframe = 1 - Enemy.animframe
         ELSE
            Enemy.animframe = Enemy.animframe + 1
            IF Enemy.animframe >7
               DELETE Enemy
            ENDIF
         ENDIF
      ENDIF
      IF Enemy
         Enemy.ypos = Enemy.ypos - Enemy.speed
         IF Enemy.ypos <15
            GameOver = TRUE
            DELETE Enemy
         ENDIF
      ENDIF
   NEXT
   
ENDFUNCTION

Regards,
johngood.

Code (glbasic) Select

compiling:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::DrawEnemies()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:221: error: no match for call to `(__GLBASIC__::SpiderData) (int)'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:247: error: no matching function for call to `DIMDEL(__GLBASIC__::SpiderData&, int&)'
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:788: note: candidates are: void __GLBASIC__::DIMDEL(__GLBASIC__::DGIntArray&, int)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:798: note:                 void __GLBASIC__::DIMDEL(__GLBASIC__::DGNatArray&, int)
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:255: error: could not convert `Enemy' to `bool'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:266: error: no matching function for call to `DIMDEL(__GLBASIC__::SpiderData&, int&)'
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:788: note: candidates are: void __GLBASIC__::DIMDEL(__GLBASIC__::DGIntArray&, int)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:798: note:                 void __GLBASIC__::DIMDEL(__GLBASIC__::DGNatArray&, int)
*** FATAL ERROR - Please post this output in the forum
Title: Re: Blitz Basic to GLBasic
Post by: MrTAToad on 2009-Oct-02
Try
Code (glbasic) Select
FOREACH enm IN  Enemy[], and replace all enemy.xxx statements with enm.xxxx

You are trying to use a variable that has already been defined as an array
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Oct-02

The Errors are getting smaller or is it that I am getting older. ;/
Why was I getting Enemy bool  Error in my earlier posts
The Error is still there enm bool Error because I replaced Enemy with enm?

Regards,
johngood.




Code (glbasic) Select

compiling:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::DrawEnemies()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:255: error: could not convert `Enm' to `bool'
*** FATAL ERROR - Please post this output in the forum
Title: Re: Blitz Basic to GLBasic
Post by: Kitty Hello on 2009-Oct-02
case sensitivity ;)
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Oct-03
Hi,
Why am I getting the following Precompiling Error?

C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::DrawEnemies()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:255: error: could not convert `Enm' to `bool'

It has been there in all the above Precompiling outputs.  :sick:

johngood
Title: Re: Blitz Basic to GLBasic
Post by: MrTAToad on 2009-Oct-03
Enm sounds like it hasn't been defined locally

Try (in the appropriate function) :

Code (glbasic) Select
LOCAL Enm as SpiderData
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Oct-03
Hi MrTAToad,

Thanks for persisting with me.  =D

Here are my declarations and the Function


TYPE SPIDERDATA
   xpos
   ypos
   animframe
   animcount
   animpause
   speed
   hit
ENDTYPE

GLOBAL spiderdata[] AS SPIDERDATA

GLOBAL Enemy[] AS SPIDERDATA


FUNCTION DrawEnemies:
LOCAL Enm AS SPIDERDATA  // also tried spiderdata
   FOREACH Enm IN  Enemy[]
      DRAWANIM 8,Enm.animframe,Enm.xpos,Enm.ypos
      Enm.animcount = Enm.animcount + 1
      IF Enm.animcount > Enemy_Anim_Pause
         Enm.animcount = 1
         IF Enm.hit = FALSE
            Enm.animframe = 1 - Enm.animframe
         ELSE
            Enm.animframe = Enm.animframe + 1
            IF Enm.animframe >7
               DELETE Enm
            ENDIF
         ENDIF
      ENDIF
      IF Enm
         Enm.ypos = Enm.ypos - Enm.speed
         IF Enm.ypos <15
            GameOver = TRUE
            DELETE Enm
         ENDIF
      ENDIF
   NEXT
ENDFUNCTION


Regards,
johngood.

Code (glbasic) Select

compiling:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::DrawEnemies()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:274: error: could not convert `Enm' to `bool'
*** FATAL ERROR - Please post this output in the forum
Title: Re: Blitz Basic to GLBasic
Post by: MrTAToad on 2009-Oct-03
The problem is :
Code (glbasic) Select
IF Enm

Enm will always exist, so checks for existence wont work.  Thus, the function becomes :

Code (glbasic) Select
FUNCTION DrawEnemies:
LOCAL Enm AS SPIDERDATA  // also tried spiderdata
   FOREACH Enm IN  Enemy[]
      DRAWANIM 8,Enm.animframe,Enm.xpos,Enm.ypos
      Enm.animcount = Enm.animcount + 1
      IF Enm.animcount > Enemy_Anim_Pause
         Enm.animcount = 1
         IF Enm.hit = FALSE
            Enm.animframe = 1 - Enm.animframe
         ELSE
            Enm.animframe = Enm.animframe + 1
            IF Enm.animframe >7
               DELETE Enm
            ENDIF
         ENDIF
      ENDIF
     
     Enm.ypos = Enm.ypos - Enm.speed
     IF Enm.ypos <15
        GameOver = TRUE
        DELETE Enm
     ENDIF
   NEXT
ENDFUNCTION
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Oct-03
Thanks to you MrTAToad. :good:

That fixed that error!

I do hope you are not going on holiday as I still have four Functions to debug! ;/

Thanks once again for your much needed help.

Best Regards,
johngood.

Title: Re: Blitz Basic to GLBasic
Post by: MrTAToad on 2009-Oct-09
Dont worry - I'm around.
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Oct-10
Hi it's me again  O_O
At the moment I am working another game and I am Having more problems with TYPE'S again  :sick:

I have created this small program to simplify debugging
if I enable the line PRINT Ship.xpos,100,130 I get the Error below!

With the same line commented out all is fine even the call to InitShip()
does not generate any Errors!
The same happens with Pilot[]
I have also tried it in Version 7.138, no difference.

Regards,
johngood.



Code (glbasic) Select


// --------------------------------- //
// Project: TypeProblem
// Start: Saturday, October 10, 2009
// IDE Version: 6.248

GLOBAL mx%, my%, imouse%, b1%, b2%

TYPE tMouse
x%
y%
active%
ENDTYPE
GLOBAL Mouse[] AS tMouse

DIM Mouse[5]

TYPE SHIP
    xpos
    ypos
    enabled
ENDTYPE

GLOBAL Ship[] AS SHIP
GLOBAL Pilot[] AS SHIP



SETSCREEN 640,480,0
LIMITFPS 30
InitShip()

// Main loop
WHILE KEY(1) = FALSE
UpdateMice()
PRINT "Mouse  X   Y",40,70
PRINT Mouse[0].x, 100,100
PRINT Mouse[0].y, 130,100
//PRINT Ship.xpos,100,130
SHOWSCREEN

WEND



FUNCTION InitShip:
LOCAL dumy AS SHIP
dumy.xpos = 240
dumy.ypos = 600
dumy.enabled = 1
DIMPUSH Ship[], dumy
ENDFUNCTION

FUNCTION UpdateMice:
MOUSESTATE mx,my,b1,b2
Mouse[0].x = mx
Mouse[0].y = my
ENDFUNCTION







compiling:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:24: error: 'class __GLBASIC__::DGArray<__GLBASIC__::SHIP>' has no member named 'xpos'
*** FATAL ERROR - Please post this output in the forum
Title: Re: Blitz Basic to GLBasic
Post by: Moru on 2009-Oct-10
Ship[] is an array but you call it as a variable. You need to type:
PRINT Ship[n].xpos, 100, 130

n = the ID of the ship
Title: Re: Blitz Basic to GLBasic
Post by: johngood on 2009-Oct-11
Thanks Moru,
Thats what happens when you block copy TYPE definitions!   ;/

The ship array should have been:
Global  ship AS SHIP

As there is only one ship in the game.

regards,
johngood