GLBasic forum

Main forum => GLBasic - en => Topic started by: Leon on 2015-Oct-20

Title: own Commands in GLBasic?
Post by: Leon on 2015-Oct-20
Hello,
is it possible to define own commands such as DRAW instead of DRAWSPRITE or LOAD instead of LOADSPRITE or something like that? I don't want to do such things with functions. Is it possible?
Thanks in advance
Title: Re: own Commands in GLBasic?
Post by: spacefractal on 2015-Oct-20
No, functions is the Way to do....
Title: Re: own Commands in GLBasic?
Post by: Ian Price on 2015-Oct-21
As SF said functions are really the only easy way to do that eg.

Code (glbasic) Select

FUNCTION draw(x%,y%,image%)
DRAWSPRITE image,x,y
ENDFUNCTION


Do you not like the syntax, or are you used to something a bit different?
Title: Re: own Commands in GLBasic?
Post by: Leon on 2015-Oct-21
Thanks for your answers. :)
Actually, I like the syntax but there is a program for the Nintendo 3DS called SmileBASIC that allows you to write games on the 3DS in basic. I wanted to write a simple wrapper so you could use the project made with SmileBASIC and export it to other platforms by using GLBasic.
Title: Re: own Commands in GLBasic?
Post by: erico on 2015-Oct-21
Nice idea Leon! :good:
Title: Re: own Commands in GLBasic?
Post by: Leon on 2015-Oct-21
Thanks :)
Unfortunately, I don't know how to "create" own names for commands. I can't use functions for this because then it isn't a wrapper anymore since you can't use the commands used in SmileBASIC without adding "()" at the end of each command.
Title: Re: own Commands in GLBasic?
Post by: Ian Price on 2015-Oct-21
Actually, I had thought of doing exactly the same thing with regard to SmileBASIC, although I wanted to be able to write SmileBASIC programs on a pc, rather than the clunky touchscreen input method.

I recently bought a US 3DS purely to play Snapdots (a Guru Logic game that wasn't released in Europe) and other US only treats.

As a fan of the original 2DS only PetiteBASIC, I just had to buy the new version, which isn't available in Europe and don't know when it will be. So my US 3DS purchase worked out very well. The original PetiteBASIC had a VERY buggy pc interface that you could write code in that you could transfer to the DS.

There is a SmileBASIC competition going on right now (right through to January) - are you planning on entering?
Title: Re: own Commands in GLBasic?
Post by: Leon on 2015-Oct-21
No, I'm not going to take part in it as I still have to wait till SmileBASIC's release in Europe :(
Are you going to enter?
I wanted to write the wrapper for Petit Computer and rewrite the wrapper as soon as SmileBASIC was released in Europe.
You wanted to do the same thing?  :D
Do you have an idea how to do this?
Title: Re: own Commands in GLBasic?
Post by: Ian Price on 2015-Oct-21
I have ideas, but not the time. I'd rather concentrate on making games though.

As for entering the comp, I'm not working on anything right now, but I have been giving it some serious thought.
Title: Re: own Commands in GLBasic?
Post by: Leon on 2015-Oct-21
Could you tell me what your ideas to achieve a wrapper for it are? :)
Or are they extremely complex?
Title: Re: own Commands in GLBasic?
Post by: Ian Price on 2015-Oct-21
It wouldn't be a wrapper as such, more an IDE created with GLB. Not sure how feasible or even possible it would be, but needless to say it would be quicker to do it than explain it.
Title: Re: own Commands in GLBasic?
Post by: erico on 2015-Oct-21
That is a nice plan Ian, so you would create an ide+parser to read text code from the smilebasic, and then compiling would translate that text to glbasic equivalent in functions? So it is more of a translator then a wrapper?
Title: Re: own Commands in GLBasic?
Post by: Ian Price on 2015-Oct-21
Yep. :)
Title: Re: own Commands in GLBasic?
Post by: Leon on 2015-Oct-21
Wow! Pretty good idea. :)
But that's really hard to achieve (at least for me  :( )
Title: Re: own Commands in GLBasic?
Post by: spacefractal on 2015-Oct-21
Was it not a glbasic compiler for smile basic? Not that other way?

That platform is interesting.

I'm would property do a wrapper compiling in blitz max to translate the syntax, which is great for this kind of uses, not glbasic it's self. This is to avoid folder clutter and etc, which can been annoying for tools.  I'm did that for small tools for Android and ios for automate icons and such ting.

Title: Re: own Commands in GLBasic?
Post by: erico on 2015-Oct-21
Quote from: Leon on 2015-Oct-21
Wow! Pretty good idea. :)
But that's really hard to achieve (at least for me  :( )

Maybe not, you could focus on the parsing of text and the function populating alone and use the likes of a notepad for the editor.
You could also output GLB equivalent to another text file, then you copy and paste into the glb ide and compile.
You can later take a look on the extras.

Matchy once did a painter in GLB that outputs trs-80 color basic code, that then you would copy and paste to an emulator, or type on the real machine, and the image would pop up. :good:

You may want to check this thread:
http://www.glbasic.com/forum/index.php?topic=9675.105
Title: Re: own Commands in GLBasic?
Post by: MrPlow on 2015-Oct-22
 :happy: Never knew this was coming and so popular :)

Just finishing off my book of basic games for Sinclair BASIC. :)

Maybe a script in a text editor could reformat the code with function brackets

If <command> is found then replace first <space> with ( and append ) to end of line.

Or something like that...not familiar with the smile syntax myself - used petite a few times.


Title: Re: own Commands in GLBasic?
Post by: matchy on 2015-Oct-22
As erico kindly mentioned, it's very useful to create utilities to just produce code for classic 80s BASIC. There was a cool BBC interpreter and maybe some Turtle Logo I've seen on the board. The idea of cutting old code, parsing it and having it run sounds real cool, even if you covert/translate/invent your own terms.

Anyhow, I'm going to try an answer the question in the most practical way if precise commands aren't required. To replace DRAWRECT and reduce the parameter parsing efficiency, I use my own type class

Code (glbasic) Select

rect.draw()


Here is an example.

Code (glbasic) Select


TYPE _rect
x
y
width
height
color
texture
FUNCTION draw:
IF self.texture <> -1
STRETCHSPRITE self.texture, self.x, self.y, self.width, self.height
ELSE
DRAWRECT self.x, self.y, self.width, self.height, self.color
ENDIF
ENDFUNCTION
ENDTYPE

TYPE _scene
rect AS _rect
FUNCTION begin:
self.rect.x = 10
self.rect.y = 20
self.rect.width = 30
self.rect.height = 40
self.rect.color = 0xff0000
self.rect.texture = -1
WHILE TRUE
CLEARSCREEN
self.rect.y = 20
INC self.rect.y, SIN(GETTIMERALL()) * 10
self.rect.draw()
SHOWSCREEN
WEND
ENDFUNCTION
ENDTYPE

GLOBAL scene AS _scene
scene.begin()

Title: Re: own Commands in GLBasic?
Post by: Leon on 2015-Oct-22
Quote from: erico on 2015-Oct-21
Quote from: Leon on 2015-Oct-21
Wow! Pretty good idea. :)
But that's really hard to achieve (at least for me  :( )

Maybe not, you could focus on the parsing of text and the function populating alone and use the likes of a notepad for the editor.
You could also output GLB equivalent to another text file, then you copy and paste into the glb ide and compile.
You can later take a look on the extras.

Matchy once did a painter in GLB that outputs trs-80 color basic code, that then you would copy and paste to an emulator, or type on the real machine, and the image would pop up. :good:

You may want to check this thread:
http://www.glbasic.com/forum/index.php?topic=9675.105


Good idea but I have never written a parser or read a tutorial about it so I don't even know how to program a parser :(
Could somebody explain me how a parser works? I know what it does (at least I think I do  ;/)
Title: Re: own Commands in GLBasic?
Post by: matchy on 2015-Oct-22

Could somebody explain me how a parser works?
[/quote]

Simply, how about a classic text adventure because it's more fun? For example, LOOK SHELF, GET BOOK, GO UP. Split those two words combo (verb and noun) and processes them with select cases!
Title: Re: own Commands in GLBasic?
Post by: erico on 2015-Oct-23
Wiki has some good answers.
https://en.wikipedia.org/wiki/Parsing

But to simplify, it means to analyse text.
I think the most simple way to experience it, is with what Matchy just proposed, do a text adventure (Interactive Ficction).