BASIC

Author Topic: Graphic bug I can't understand!  (Read 5439 times)

Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
Graphic bug I can't understand!
« on: 2010-Jul-28 »
Dear all,

I need your help to explain me the bug I found.

The attached file is the source of the game I wrote "SimOniZ".
THe attached version has no problem... after I discovered a workaround for the bug.

In the source files, I declares global constants for the sprite ids of the grafix components.
e.g. in the play.gbas file
Code: GLBasic [Select]
// grafix components
GLOBAL GFX_GREEN%       = 0 ;  // Green button
GLOBAL GFX_YELLOW%      = 1 ;
GLOBAL GFX_BLUE%        = 2 ;
GLOBAL GFX_RED% = 3 ;
GLOBAL GFX_PAUSE%       = 4 ; // Pause button
GLOBAL GFX_STATUS%      = 5 ;
GLOBAL GFX_FONT15%      = 100 ;
 

To reproduce the bug, open the project and edit the credits.gbas file
Code: GLBasic [Select]
//-----------------------------------------------------------------------------
// C O N S T A N T S
//-----------------------------------------------------------------------------

// menu states
GLOBAL MS_NONE%         = 0;
GLOBAL MS_BACK%         = 1 ;

// grafix components
GLOBAL GFX_BACK%        = 0 ;   // Bouton "Back"
GLOBAL GFX_FONT15%      = 100 ;

Replace the line
Code: GLBasic [Select]
 GLOBAL GFX_FONT15%     = 100 ;
by
Code: GLBasic [Select]
 GLOBAL GFX_FONT15%     = 1 ;

This change generates the following problem:
* in the play screen, the yellow button is not displayed
* in the pause screen, the abort button is not displayed

Doing the same change in the highscores.gbas does not cause the bug!

I am completely lost.

Thanks for the time you will spent to explain me what is going wrong!

François

[attachment deleted by admin]

Offline okee

  • Dr. Type
  • ****
  • Posts: 324
    • View Profile
Re: Graphic bug I can't understand!
« Reply #1 on: 2010-Jul-28 »
why do you have a semicolon after every statement ?

Isn't Global exactly that? Global across all the files in your project
so if you declare Global variables in your main project file the other
files in your project will have access to them. You were declaring
GLOBAL GFX_FONT15%  = 1 in one file and
GLOBAL GFX_HIGHSCORES%    = 1 ; in another file

If 1 is being used for the id of an image then the last declaration
that the compiler reads will be given the id 1,
The best bet is declare all your global variables in your main file
and give each of the image variables a unique number
« Last Edit: 2010-Jul-28 by okee »
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
Re: Graphic bug I can't understand!
« Reply #2 on: 2010-Jul-28 »
Hi,

Defined in the main file globals are accessible anywhere, but defined in a source file they can only be accessed in that file.

Furthermore, everytime I call the main routine of a source file, I loadanim the grafix components, overriding the previous anim with the same id.

Finally, why  does the green button (GFX_GREEN% = 0) not show the same bug?

Offline okee

  • Dr. Type
  • ****
  • Posts: 324
    • View Profile
Re: Graphic bug I can't understand!
« Reply #3 on: 2010-Jul-28 »
Quote
Defined in the main file globals are accessible anywhere, but defined in a source file they can only be accessed in that file.
I just did a test but I'm using GLB v 8.0 and a global declared in an included file is available to the main file.
So I think if you declare a global in any file it's global across all
but if you declare as local (outside a function or sub) it's just available withing that file
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
Re: Graphic bug I can't understand!
« Reply #4 on: 2010-Jul-28 »
Defining
Code: GLBasic [Select]
 LOCAL GFX_FONT15%      = 1 ;

returns

Code: GLBasic [Select]

_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.6.973 SN:126b5585 - 3D, NET
"credits.gbas"(17) error : command not inside function or sub
 

I use GLB 8 too

If I write
Code: GLBasic [Select]
// grafix components
GLOBAL GFX_BACK%        = 1 ;   // Bouton "Back"
GLOBAL GFX_FONT15%      = 0 ;
 

Then it is the green button that shows the bug, not the yello  :S
« Last Edit: 2010-Jul-28 by François Vanzeveren »

Offline okee

  • Dr. Type
  • ****
  • Posts: 324
    • View Profile
Re: Graphic bug I can't understand!
« Reply #5 on: 2010-Jul-28 »
Ok sorry didn't test Local :) yeah that gives an error outside a function in an included file
but Global is ok

main file
Code: GLBasic [Select]
SETSCREEN 800,600,1
GLOBAL Name$ = "Mary"

WHILE KEY(1) <> 1
        editname()
        PRINT Name$,100,100
        PRINT SurName$,100,150
        SHOWSCREEN

WEND

included file
Code: GLBasic [Select]
GLOBAL SurName$ = "Krypton"

FUNCTION editname:

        Name$ = Name$ + "s"

ENDFUNCTION
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
Re: Graphic bug I can't understand!
« Reply #6 on: 2010-Jul-28 »
Quote
Defined in the main file globals are accessible anywhere, but defined in a source file they can only be accessed in that file.
I just did a test but I'm using GLB v 8.0 and a global declared in an included file is available to the main file.
So I think if you declare a global in any file it's global across all
but if you declare as local (outside a function or sub) it's just available withing that file

I made the test

Main file:
Code: GLBasic [Select]
GLOBAL a;

a = 1;

GOSUB test2 ;

PRINT a, 100, 100;

PRINT b, 200, 100;

SHOWSCREEN;

MOUSEWAIT;
 

Source file test2.gbas
Code: GLBasic [Select]
GLOBAL b;

SUB test2:
b = 2 ;
ENDSUB
 

Code: GLBasic [Select]

_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.6.973 SN:126b5585 - 3D, NET
"test.gbas"(17) error : variable is not explicitly defined : b

 

I conclude that b is "global" only within test2.gbas...

Offline okee

  • Dr. Type
  • ****
  • Posts: 324
    • View Profile
Re: Graphic bug I can't understand!
« Reply #7 on: 2010-Jul-28 »
Hmm... it will work if you give it a value ?
GLOBAL b = 2
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
Re: Graphic bug I can't understand!
« Reply #8 on: 2010-Jul-28 »
GOOD! You are right!

Code: GLBasic [Select]
GLOBAL b = 3;

SUB test2:
b = 2 ;
PRINT a, 250, 300 ;
ENDSUB
 

In the main file, b equals 2

Weird!!!!

Offline okee

  • Dr. Type
  • ****
  • Posts: 324
    • View Profile
Re: Graphic bug I can't understand!
« Reply #9 on: 2010-Jul-28 »
I think it would be worth giving all your GFX variables a unique number
I'd say that would solve your problem.
P.S the semi colon ?  is that a habit from pascal programming ?
didn't even know GLB could take them :)
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
Re: Graphic bug I can't understand!
« Reply #10 on: 2010-Jul-28 »
I think it would be worth giving all your GFX variables a unique number
I'd say that would solve your problem.
P.S the semi colon ?  is that a habit from pascal programming ?
didn't even know GLB could take them :)

The semi-colon, an old habit of the C time :)

MrTAToad

  • Guest
Re: Graphic bug I can't understand!
« Reply #11 on: 2010-Jul-29 »
You should be using GENSPRITE for loading sprites to guarantee a number that is free.  That will also prevent a sprite being replaced by loading into an index that already has a sprite.

In addition, if you are going to use a variable just for storing these indexes, you might as well use CONSTANT for extra coding protection.


Offline François Vanzeveren

  • Mc. Print
  • *
  • Posts: 45
    • View Profile
Re: Graphic bug I can't understand!
« Reply #12 on: 2010-Jul-29 »
THanks to okee and MrTAToad...

By the way, what do you think about the code structure put in place in my project? Do you have suggestions to improve the structure? I tried by a complete code refactoring of SimOniZ to reach a kind of game "template" easily maintainable and reusable for other projects.

Thanks!

MrTAToad

  • Guest
Re: Graphic bug I can't understand!
« Reply #13 on: 2010-Jul-29 »
I would do all the loading of sprites etc in one place, rather than split over the many files.

Apart from that it is nicely laid out.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5028
  • O Rly?
    • View Profile
Re: Graphic bug I can't understand!
« Reply #14 on: 2010-Jul-29 »
GLOBAL b = 3 WORKS, Ocean ! You can do that....


NEVER call functions with GLOBAL:

GLOBAL b = foo() //<----- BAM, doesen't work!

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