Hello friends,
I'm with GLBasic since a few months and is an easy language, but I have some questions (doubts). I prefer to put in one post, instead create many separated posts.
1- When you declare a GLOBAL variable you can't access it from other file Ã,¿isn't it?
I have read that you can declare again in the other file, but I think this will be a different variable. Instead Types are shared and I have no problem.
2- Related with the first, sometimes you think that you are using a global variable in another file,
but you are using a new variable autodeclared when are used. This make me crazy.
Ã,¿Are any comand or option to force to declare variables before are used, like "Option Explicit" in Visual Basic?
3- Sometimes I load a font with LOADFONT and not shows nothing in PRINT, I use SETFONT and SHOWSCREEN too. With other fonts works ok. All fonts are created with the DingsFont tool.
Greetings
1. You can share globals in other source files. If the compiler complains, just tell it that you are aware of the existance by saing:
GLOBAL gTheVarname%
2. The menu "Project/Options" has the "explicit" checkbox
3. Post the font file (preferably the .glfont you can save in DiNGSfont, too)
Thanks for the answers.
This is the font that not works, prints garbled blocks: smallfnt.png, I try to change de filename but is the same. I have another similar font that works ok, is the mediumfnt.png. I include the .glfont with .txt to include in the post.
[attachment deleted by admin]
That first font file makes garbled text for me too, it's like the line-height isn't correct. If I change to 256 characters in the font, it works fine again.
Mabe there should be an extra parameter to the LOADFONT command that tells GLBasic if it's a 128 or 256 character font?
oh no!!! The font, though 128 chars is higher than wide. Make a 256 character font and you're set.
This means that LOADFONT thinks that is a 256 chars font. At least we know the reasons of the garbled text. Thanks.
Regarding global variables when using explicit declarations...
When explicit declarations are turned on, GLB won't accept global variables or types defined inside functions/subs.
I use separate source file for global variables, but can't declare global types that way.
Where else could I place my type-definitions except at the beginning of main source file (that's messy)?
EDIT:
Never mind, I think I got it...
It's the sequence of hoe functions are declared/written that counts, not order of how they're called.
Example:
This won't compile in explicit mode ("variable is not explicitly defined: glob"), while in non-explicit mode it returns 0 for global variable.
types()
globals()
main()
FUNCTION main:
PRINT "Global = " + glob,0,0
PRINT "Type value = " + tip.value, 0,20
SHOWSCREEN; KEYWAIT
ENDFUNCTION
FUNCTION types:
TYPE DTip
value = 2
ENDTYPE
GLOBAL tip AS DTip
ENDFUNCTION
FUNCTION globals:
GLOBAL glob = 1
ENDFUNCTION
While this compiles perfectly:
types()
globals()
main()
FUNCTION types:
TYPE DTip
value = 2
ENDTYPE
GLOBAL tip AS DTip
ENDFUNCTION
FUNCTION globals:
GLOBAL glob = 1
ENDFUNCTION
FUNCTION main:
PRINT "Global = " + glob,0,0
PRINT "Type value = " + tip.value, 0,20
SHOWSCREEN; KEYWAIT
ENDFUNCTION
Conclusion: elders were right when they've told us global variables are devil's work! >:D
It should work. :(
oops, I edited my post while you were replying...
I have bad luck!! Fonts with black text are showed good in PC, but not in the Wiz. Not writes nothing. I use the same fonts and use pink as transparent colour. If I change the font colour to other works good.
Fonts are loaded with black (rgb 0, 0, 0) as transparent, if you change the transparent color (SETTRANSPARENCY) before, it should work. You could also make your font almost black, very dark gray rgb(1,1,1).
I made more tests about the fonts in the Wiz. If you use a font with black characters and other colour (pink) background using as transparente colour, works in PC, but not works in Wiz and GP2X. Both colours, black and pink background shows transparent in this platforms. This is a bug. :S
Then I change the font colour with RGB(0,0,1) but not works too. Investigating I discovered a trick: I'm using 16 bpp where the colours are coded in RGB565 bits scheme (in Wiz). 8 bits - 5 = 3 bits are lost (shifted to the right) when the screen colours are compound. Then RGB(0,0,1) are codified with the same bits as RGB(0,0,0). Then the darkest different colour can be RGB(0,0,8), because 8 is 2^3. With this colour in the font works in Wiz too. I'm happy now. =D
@doimus > I noticed that as well. For some reason globals must be at the start of the file. they can be sprinkled throughout functions but for some reason they must be listed first.
I program the same as you - I always use an Init function to declare my variables. And I noticed that this morning as well.
Additionally I've had a few instances where I can't use: "filename\" in a string, I have to use "filename" + chr$(42) - which is odd.
Try "filename\\" in your string instead.
Well, once I figured out what was causing the compiling problem - I reworked the code not to use \ anyway. If it is to be platform independant it needs to alternate between \ and / depending on the OS. And I had two choices. Detect the platform or just tweak the code a bit.
it made more sense just to tweak the code. :)
KermEd, you can use "/" always I use in Windows and Wiz (Linux) and works Ok.
Now, can we return to my topics please? :)
In GLBasic, _always_ use "/". Even on Windows.
I think the point was that the "/" "\" characters were being removed from his string, hence why I stated he should duplicate the character.
\ introduces a special character (excape character)
You can write \\ to get \, and \n for a newline and such.
No worries, it was just something I noticed :) But I know hardyx had some questions in this thread and I seemed to have somehow hijacked it.
Something to do with Setting-Transparency having issues on the GP2X-Wiz. I can't really replicate it myself - I use GIMP for my .png files and I never had any transparency issues. I do know that faded 32bit alpha has issues (it resolves to a 24bit transparency - meaning all or nothing) - but thats a Wiz limitation I believe not anything to do with GLBASIC. And its easy for me to code around.