Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Moru

#21
Simple splitting function that splits strings the way expected from PHP and similar languages.

splitstr(";a;b;;d;", array[], ";")
gives:
0 = ""
1 = "a"
2 = "b"
3 = ""
4 = "d"
5 = ""


Code (glbasic) Select
// Splits strings into an array, does not skip empty fields or split-characters as first/last on a line
// Considers double split-characters as an empty field ("a;b;;d") = four fields
FUNCTION splitstr2: string$, array$[], split$
LOCAL a$, n, length, found
REDIM array$[0] // Empty the array

length = LEN(string$)

WHILE n<=length
found = INSTR(string$, split$, n) // Find next delimiter

IF found>=0
a$ = MID$(string$, n, found-n) // Find the data
DIMPUSH array$[], a$ // Add it to the field in the array
n = found+1 // Next field
ELSE
a$ = MID$(string$, n, -1) // Find the data
DIMPUSH array$[], a$ // Last field, add to the array
n=length+1
ENDIF
WEND
RETURN LEN(array$[])
ENDFUNCTION
#22
Splitstr() seems to ignore empty fields when splitting a string. See below example

Code (glbasic) Select
LOCAL array$[], n
SPLITSTR(";a;b;     ;d;;f;", array$[], ";")
FOREACH a$ IN array$[]
STDOUT n + ": " + a$ + "\n"
INC n
NEXT
KEYWAIT
END



Code (glbasic) Select

Output:
0: a
1: b
2: d
3: f

Expected output:
0:
1: a
2: b
3: <lots of spaces>
4: d
5: <zero-length string>
6: f
7: <zero-length string>


When reading listings it would be preffered if the splitting doesn't skip empty fields since you have no idea if your fields are the correct ones then.
#23
This is for you, Bigsofty :-)

Keeps backups to as many generations as you want. Just change the variable "backups" to how many backups you want. I hope this works for you too, seems to work well enough for me so far but isn't overly tested since it was a 30 min job before bed... :-)

It will create a subdirectory in your project folder called "backups" and in this one there will be even more subfolders, as many as you specify in the variable. The highest number will always be filled with the latest backup, all others move one step down for each backup-run. 5 becomes 4 and so on. It's done with the move command so should be almost instant no matter how many files are in those folders.

Put this on a macro and call it before every compile. Would be handy with a macro that always runs automaticly before and after a compile. I thought there was such a thing but I can't find it?

Code (glbasic) Select
:: Manage backups
:: By Moru
:: http://gamecorner.110mb.com
:: ---------------------------

:: How many backups do you want:
SET backups=7

:: Create the folders
FOR /l %%x IN (1, 1, %backups%) DO IF NOT EXIST "%GLB_PROJ_PATH%\backups\%%x" MKDIR "%GLB_PROJ_PATH%\backups\%%x"

:: Remove first
RMDIR /S "%GLB_PROJ_PATH%\backups\1" /Q

:: Rename the rest to replace the first moving the backups one point down the ladder
FOR /l %%x IN (2, 1, %backups%) DO CALL :do_move %%x

:: Create the last folder again
IF NOT EXIST "%GLB_PROJ_PATH%\backups\%backups%" MKDIR "%GLB_PROJ_PATH%\backups\%backups%"

:: Copy all sourcefiles to this last folder
:: change .gbas to "*" if you want backup of all files, not just the .gbas
:: add /S to copy subfolders too (this will make it a lot slower but keep backup of the exe-file and all media too)
:: Add /A to only copy changed files. I don't recommend this since it will move out the file from the backup-set sooner or later and there won't be more backups of this file)
XCOPY "%GLB_PROJ_PATH%\*.gbas" "%GLB_PROJ_PATH%\backups\%backups%" /Q


EXIT
EXIT

:: -------------------------
:: Do the moving of a folder
:: -------------------------
:do_move

    :: The ID of the target folder (move each folder down one step, 2 becomes 1)
    SET /a ny=%1-1

    MOVE "%GLB_PROJ_PATH%\backups\%1" "%GLB_PROJ_PATH%\backups\%ny%"

GOTO :EOF
#24
I'm still having slight troubles with polyvector on GP2X. They show up but I get the texture one or two pixels to the right if I specify a smaller area of a sprite to draw. This works as expected on win32 but not on GP2X, see the screenshots below. A test-project is included.

[attachment deleted by admin]
#25
Bug Reports / Exit in GP2X
2009-Oct-19
I'm having troubles quitting from an application on GP2X. If I press the volume + and - buttons it just locks up. Same if I set up the start button to quit.

I'm also having troubles drawing with polygons on GP2X. Nothing shows up. I included the project with simple source and precompiled for GP2X. Works fine on the PC, works on GP2X but hangs up when quitting, no polygon showing up.

Code (glbasic) Select
// --------------------------------- //
// Project: GP2X Test
// Start: Monday, October 19, 2009
// IDE Version: 7.145

LOADFONT "smalfont.png", 1
SETFONT 1

LOCAL y1%, y2%

WHILE KEY(28) = 0
STARTPOLY -1
POLYVECTOR 0,0,     0,0, RGB(255,255,255)
POLYVECTOR 0,239,   0,0, RGB(100,200,255)
POLYVECTOR 319,239, 0,0, RGB(255,255,255)
POLYVECTOR 319,0,   0,0, RGB(255,255,0)
ENDPOLY
PRINT "Test, should be light background", 0, 10
y1 = RND(20)
y2 = RND(20)
DRAWLINE 0,y1+50,319,y2+50, RGB(0,255,0)
DRAWLINE 0,y2+50,319,y1+50, RGB(255,0,0)
SHOWSCREEN
WEND



[attachment deleted by admin]
#26
Any chance for a command similar to the one in VB, I think it was called "WITH". This makes it easer to use a type that you need to use many times within a code block. Can also use with deeply nested types.

Usage like this:

Code (glbasic) Select
TYPE tAtype
    x; y
ENDTYPE

GLOBAL theType as tAtype

WITH theType
    .x = 50
    .y = 150
ENDWITH
#27
I'm having problems with alphamode again. When I use it in 2D no problems but in 3D drawing several objects on top of eachothers there is no blending if the camera is placed straight in front of the objects (0,0,-50 -> 0,0,0). However if I move the look at point slightly up or down the objects starts blending. I have tried moving some objects a little bit further back or in front with no difference.

Here is the code, use the mouse to move the middle square, buttons for aiming the camera up or down. As you might notice not all objects are blending the whole time, it depends on where the center square is placed. Try moving it around a bit.

Code (glbasic) Select
SETTRANSPARENCY RGB(0,0,0)

DRAWRECT 5,5,22,22,RGB(128,128,128)
GRABSPRITE 1, 0,0, 32,32

LOCAL mx, my, b1, b2

WHILE TRUE
PRINT "Move the mouse!", 5, 5
mx = mx + MOUSEAXIS(0)
my = my + MOUSEAXIS(1)
IF MOUSEAXIS(3) THEN INC look_at, 0.1
IF MOUSEAXIS(4) THEN DEC look_at, 0.1

X_MAKE3D 1, 1000, 45
X_CAMERA 0, 0, -50, 0, look_at, 0
X_AMBIENT_LT 0, RGB(255,255,255)
ALPHAMODE .4

X_SPRITE 1,      8,      0, 0, 1
X_SPRITE 1,     -8,      0, 0, 1
X_SPRITE 1, -mx/10, -my/10, 0, 1
X_SPRITE 1,      0,      8, 0, 1
X_SPRITE 1,      0,     -8, 0, 1
//X_DRAWAXES 0, 0, 0
SHOWSCREEN
WEND
#28
This program parses your code and indent each line properly. The comments at the end of lines are nicely aligned to improve readability and comments that start too far to the right are places alone on the previous line instead. All you need to do is call the program with the filename(s) in the parameters.

Examplecode for the macro system in GLBasic v7 is included. It won't destroy your original file, it just creates two more files, one called "filename.gbas.new" and the second called "filename.gbas.rem". The first one is the first pass, only indenting each line correctly. The second has also aligned the comments on the end of all lines. (you do comment your code, right? :-)

If you run the macro it will open up both files in notepad, one after the other, just edit the macro so you get the file you want. Copy/paste into your original file if you feel happy with what he did.

Please try this and leave comments here, it is not fully tested yet so please don't paste over your original code before reviewing it with some program that can compare lines for similarities. PSPad is great for this, it doesn't complain on indentation differences, only real characters so you can be sure that the code is intact.

I also try to leave INLINE/ENDINLINE blocks untouched since I can't be bothered to figure all different ways of indenting c++ code...

Beautify your code!
Have fun!
#29
It would be nice with the INC/DEC command having an optional second parameter so if you leave it out it increases by one. Nothing absolutely needed, I'm just used to it from other languages so I keep getting compiler errors when I forget :-)
#30
I made a simple example of how to make your game auto-update itself, I don't know how it is working on vista or whatever, only tried it on XP.

Simplified it does this:

  • Check what version is on the webserver (downloads a small .txt file)
  • Is it newer than what the game is?
  • Download the new .exe-file
  • Create a batfile that swaps this new exe-file for the old one and renames the old to keep a backup
  • Run the batfile that deletes itself and runs the new exe after it's done

Ofcourse it first asks the user for permission to access the net.

Code can be found on my homepage.
#31
Any of these lines (separately in a project) causes the below error. Can the channel number be max 7? Not that I need that many open at the same time, I just wanted to pick a "safe" number so I can easily include the code in new or old projects without having to change the channel number. I don't see anything in the manual about it though.

Code (glbasic) Select
OPENFILE(8, "test.txt", -1)
OPENFILE(8, "test.txt", 0)
OPENFILE(8, "test.txt", 1)


Code (glbasic) Select

_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.2009.113 - 3D, NET
Wordcount:2 commands

compiling:

linking:
success
_______________________________________
*** Finished ***
Elapsed: 1.3 sec. Time: 09:41
Build: 1 succeeded.

Start debug session.
_______________________________________
Injection started

Error:
Unknown Error:
7
#32
Bug Reports / Web issues
2009-Jun-20
These days most ISP's are blocking SMTP's outside their own area, usually you can find a relay SMTP on their homepage for using with your email program. Or just call them and complain that your email program can't send, they should know what the problem is :-)
#33
This is a way to crash the editor when compiling (a large) project:

Open "Samples\__Projects__\DDgui\DDgui.gbap" and make sure all files are open in the editor.
Press the compile button and then quickly close one of the open files.
When the compiler is done, the editor will crash. So far this works every time, on all projects I tried that are long enough for me to have time to close the window.
#34
A simple template for creating screensavers with GLBasic - for the windows platform.

http://gamecorner.110mb.com/index.php?page=screensaver

#35
Oh, another thing while I remember it... Are sprites and animations supposed to share index?
For example:
Code (glbasic) Select
LOADANIM "test.bmp", 2, 32, 32
DRAWSPRITE 2, 50, 50


Testprogram:
Code (glbasic) Select
// --------------------------------- //
// Project: test_rotate
// Start: Saturday, January 31, 2009
// IDE Version: 6.147

DRAWLINE 0,15, 50,15, RGB(255,255,255)
DRAWLINE 0,32, 50,32, RGB(255,0,0)
GRABSPRITE 1, 0,0, 64,64 // Sprite as index 1
SAVESPRITE "test.bmp", 1
LOADANIM "test.bmp", 2, 32,32 // Animation as index 2

WHILE TRUE
SMOOTHSHADING TRUE
DRAWSPRITE 2, 120,50 // Draw sprite index 2 and we get the animation sprite?
SHOWSCREEN
WEND
#36
We pretend we have an animation that contains 2 by 2 sprites and one of them has a color that isn't transparent on the edge to the other sprites. Now we want to ROTOZOOMANIM one of the other sprites, say index #0. What happens is that the border from the index #1 and #2 sprites will show up on the rotating sprite #0 (if the bordering pixel isn't transparent). See the example that only has a red border on the sprite below (#2):

(This only happens if SMOOTHSHADING TRUE is activated.)

Code (glbasic) Select

// --------------------------------- //
// Project: test_rotate
// Start: Saturday, January 31, 2009
// IDE Version: 6.147

LIMITFPS 15
DRAWLINE 0,15, 50,15, RGB(255,255,255)
DRAWLINE 0,32, 50,32, RGB(255,0,0)
GRABSPRITE 1, 0,0, 64,64
SAVESPRITE "test.bmp", 1
LOADANIM "test.bmp", 2, 32,32

phi = -90

WHILE TRUE
SMOOTHSHADING TRUE
IF KEY(203) THEN INC phi, 1
IF KEY(205) THEN DEC phi, 1
PRINT "Anim:", 50, 40
ROTOZOOMANIM 2, 0, 50,50, phi, 1
PRINT "Sprite:", 120, 40
ROTOZOOMSPRITE 1, 120,50, phi, 1
DEBUG phi + "\n"
SHOWSCREEN
WEND
#37
I'm having troubles (again) with ROTOZOOMANIM. When I rotate in 90 degree angles the rotated image looks like it got stuck somewhere between 89 and 90 degrees, run this example code and see for your self. Use left and right to rotate left and right by one degree.

Code (glbasic) Select

// --------------------------------- //
// Project: test_rotate
// Start: Saturday, January 31, 2009
// IDE Version: 6.147

LIMITFPS 15
DRAWLINE 0,15, 50,15, RGB(255,255,255)
GRABSPRITE 1, 0,0, 32,32
SAVESPRITE "test.bmp", 1
LOADANIM "test.bmp", 2, 32,32

phi = -90

WHILE TRUE
SMOOTHSHADING FALSE
IF KEY(203) THEN INC phi, 1
IF KEY(205) THEN DEC phi, 1
PRINT "Anim:", 50, 40
ROTOZOOMANIM 2, 0, 50,50, phi, 1
PRINT "Sprite:", 120, 40
ROTOZOOMSPRITE 1, 120,50, phi, 1
DEBUG phi + "\n"
SHOWSCREEN
WEND
#38
I'm no expert on SVN, just started using it at work earlier this year. But I will try to get you started and point you in the right direction where to find more information.

Why do you want SVN?

Because you want to keep track of what you do, if you want to do a big change to see if it works better you just make a new branch of the code or if you did something that totally broke your game, just reload the old code or compare the differences between the old code and the new. Every change is saved so you can always go back to any point in time that you have "committed".

Or the obvious thing, when you are more than one developer of a game you realy need this to keep organized. You can even work on the same file at the same time, you just need to run update and check the differences, then SVN should be able to patch together the two files with both your changes. (I haven't tried this though, only read about it)

How to use SVN

1. First off download these two things. If in doubt download the 32 bit Windows binaries. Install them with everything on.

SVN server and client
SVN shell for easy use (use windows explorer instead of command line :-)

2. Then decide on a safe place to store your database of changes. I usually create a folder called "svn" in the root of C:\. Inside of this I make one folder for each project I want versioned.

3. Right-click the folder you just created and select "TortoiseSVN->Create Repository Here". Repository is where SVN saves the database of changes you make. This is where your project realy will live. This folder contains everything, to remove a repository this folder is all you need to delete.

4. Now you need to import all the files you have created so far. This we do by right-clicking the folder and select "TortoiseSVN->Import". You will get a window called "Import" where you need to select the repository you created in step 3. Click the tripple-dots on the right and select it in the map-browser and then click ok.

You get a list of all files imported and then press ok

5. Make a backup of the whole original folder just in case and empty the it.

6. Rightclick the empty folder and select "SVN Checkout". Here you select the repository again and press ok. This will copy all the files from the repository to your folder for editing. Remember that this is just a copy of your project, if you don't commit your changes (right-click the folder) your changes is not in the database.

Done!

Read more here how to use SVN: SVN Book

Important notes:

Your project is now versioned and you may not rename or move files without telling SVN this. Look thru the "TortoiseSVN->" list, it is context sensitive so knows when to let you rename and move files. You can also drag files with right mousebutton to the new folder you want it and select the top line "SVN move versioned file here"


Free, online SVN book for more info and help on how to use SVN.
#39
Feedback / Some feedback
2008-Dec-16
First I want to say: I loved this when it was out originally and this looks like a very nice remake of it!

Realy like the ability to save to stand-alone file, impressive :-)

Some small things:
Player animation in 8-way mode when not steering any direction is locked to show left animation. (I don't have a joystick connected)
Why not exit testmode with escape and prevent exiting the program from the escape key, ask the user instead if he/she wants to exit.
#40
Bug Reports / INKEY$()
2008-Nov-28
I can't get INKEY$() to do what I want. Now when I'm typing and want upper case letters it will double the letter when I release the shift button.

eg: I'm typing "Hello", this will come out as "Hhello". To recreate this, run the code below:

Code (glbasic) Select
WHILE TRUE
PRINT "Enter text below!", 50, 50
a$ = INKEY$()
b$ = b$ + a$
PRINT "text: " + b$ + "|", 50, 70
SHOWSCREEN
WEND


When typing, just press and hold shift and then quicklypress any letter and fast let go of shift again and you will most of the time get double letters. Is there something I'm doing wrong?