homemade functions

BlitzMax Forums/BlitzMax Beginners Area/homemade functions

B(Posted 2009) [#1]
hey all!

is it possible to create functions in some file so that when you go into the editor
it shows up as its own function similar to the other functions already within the
program like drawtext($,x,y)?

usually I just keep all my functions with in another .bmx file and use include,
however I was wondering if there was a different way.

thanks!


plash(Posted 2009) [#2]
You mean syntax highlighting?

You could create a module and properly document it. Then whatever was documented inside the module would be (after rebuilding documentation) highlighted in MaxIDE.


B(Posted 2009) [#3]
i think thats what I mean.

basically i dont want to use includes for my own functions.


how would I create my own module and properly document it?

i am using a Mac (if that helps)

thanks for the help :)


plash(Posted 2009) [#4]
Here is one guide: http://www.blitzbasic.com/Community/posts.php?topic=42290
(Although.. it is quite old, and does not cover documentation - I think.)


B(Posted 2009) [#5]
well i did what it said and it still didnt work.

this has made me realize that its probly not the most efficient to do this.
ill just keep my functions in my source code.

thanks for all the help tho!


Brucey(Posted 2009) [#6]
If you want things to appear highlighted, you do it in a module... a bit like this :

Rem
bbdoc: summary
about: description
End Rem
Module MyDocumentedModule


Rem
bbdoc: function summary
about: function description
End Rem
Function MyFunction:Int()
End Function


Assuming your module is set up properly (see Plash's link above about making one), re-building the documentation should mean that every time you type MyFunction in the IDE, it will appear highlighted.
Also, pressing F1 while the cursor is on that word will show the summary on the status bar. Pressing F1 again, will take you to the documentation page.

It's perfectly efficient. Works for me :-)


B(Posted 2009) [#7]
darn i still cant get it to work.

im thinking it might have something todo with the part when the tutorial tells
you to open command prompt and type in the directory and then "bmk...etc"

i open up terminal, which im assuming is just like command prompt only for mac and type
it in, and i dont get any errors it seems like it worked.

however when i run my function it says
error identifier "myfunction" not found

:(


plash(Posted 2009) [#8]
You don't have to compile the module using a terminal. You just have to do 'Build Modules' in your IDE, assuming all paths are right it should compile it.

You also then have to import your module.


Brucey(Posted 2009) [#9]
the module has to be located properly too... and also the naming is important.

A small example :-)

Name of module : bah.libxml

Directory structure : BlitzMax/mod/bah.mod/libxml.mod

Name of main module file : libxml.bmx

Location of main module file : BlitzMax/mod/bah.mod/libxml.mod/libxml.mod

In libxml.bmx you would have something like this :

Module bah.libxml


That should be enough to get the module compiled properly.

ctrl-D (command-D for Mac) in the IDE should force a build of modules.


B(Posted 2009) [#10]
i have done all that.

do i have to import the module i created in the code that i write that uses the commands
i made in the module?

I can compile it just fine, but it doesnt recognize the function


OK!

so i just put:

import blah.blahmodule

(obviously not the actual name)


at the top of my source code and it worked!

it just doesnt highlight it or anything but it works.
does this help with diagnosing the problem?

B


Jesse(Posted 2009) [#11]
if you create documentation similar to what Brucey wrote in post #6 then just rebuild documentation in the Ide and it will work.


B(Posted 2009) [#12]
I have done that. Just command D right? Or control D for pc right?

Maybe I should try retarting the whole program too


Jesse(Posted 2009) [#13]
no control D rebuilds modules.
you want to rebuild documentation. It's the one you have to use the mouse with.


B(Posted 2009) [#14]
oh well maybe that is my problem then.


B(Posted 2009) [#15]
ok im still having the same problem.

i swear i did everything.


location:
name of module:     b.circle

dir structure:      BlitzMax/mod/b.mod/circle.mod

name of mod file:   circle.bmx

local of main:      BlitzMax/mod/b.mod/circle.mod/circle.mod
mod file




code in circle.bmx:
Module b.circle
Import BRL.StandardIO
Import BRL.GLMax2D


Function drawcircle(x,y,r,r1,g1,b1)
SetColor(r1,g1,b1)
DrawOval x-r,y-r,r*2,r*2
SetColor(0,0,0)
DrawOval x-r+1,y-r+1,(r-1)*2,(r-1)*2
SetColor(255,255,255)
EndFunction




i rebuilt the documentation as well as rebuilding the modules several times.

it is still saying:

Compile Error

Identifier 'drawcircle' not found




i dont know what i am doing wrong.

Im thinking its one of those small things you simply overlook once or twice. :P

please help! :)
thanks!

B


Jesse(Posted 2009) [#16]
Best I can tell you is to email it to me. I can figure it out for you and provide you with an explanation.


B(Posted 2009) [#17]
what should I email you?


Jesse(Posted 2009) [#18]
the circle.mod module


Jesse(Posted 2009) [#19]
I got your module and I looked at it. first you need to know that in order to use a module that is not included in the brl.mod, you have to declaire it import it in your programs. ea:
import b.circle

if you want it documented you need to add documentation to the module line like this:
Rem
bbdoc: makes hollow circle
EndRem
Module b.circle

any function you want to have hilite, needs to be similar, if you want them to hilite.
once you do that and your module is in the "mod" folder with the name "b.mod"
you need to open a command prompt and move to the "bin" subfolder under your blitzmax installation and type this
"docmods b.mod"
and hit <enter>
this will create the documentation.

next you need to open the bmax ide and click on the "rebuld documentation"
that should be all.
note: whenever you want to hilite a newly created instruction/command you need to include at least these three lines:
Rem
bbdoc: 
EndRem

without a blank like before the created instruction/command.

your sample program should look like this:
Import b.circle

Graphics 800,600,32

While Not KeyDown(key_escape)
Cls

drawcircle(100,100,20,255,255,255)

Flip
Wend


your module should look similar to this:
Rem
bbdoc: draw hollow circle
End Rem
Module B.Circle

ModuleInfo "Name: circle Module"
ModuleInfo "Description: circle draw"
ModuleInfo "License: none"
ModuleInfo "Authors: B"

Import BRL.Max2D

Rem
	bbdoc: Description of your function
	about: Details about what the function does
	returns: What the function returns.
EndRem
Function drawcircle(x,y,r,r1,g1,b1)
SetColor(r1,g1,b1)
DrawOval x-r,y-r,r*2,r*2
SetColor(0,0,0)
DrawOval x-r+1,y-r+1,(r-1)*2,(r-1)*2
SetColor(255,255,255)
EndFunction



I emailed you the module take a look and see what I did so you'll have a better idea on what to do.


B(Posted 2009) [#20]
ok cool!
that works great.
thanks for all the help! I get it now! :)

just one more question.

is there a way I can have it automatically imported so as not to have to have import b.circle
at the top of every program I make?

or is that not possible?


B(Posted 2009) [#21]
ok i just put the module into brl.mod and it worked so I figured it out.

thanks for everything Jesse!


xlsior(Posted 2009) [#22]
ok i just put the module into brl.mod and it worked so I figured it out.


While that works, it does have a downside: *everything* in brl.mod and pub.mod automatically gets imported in each program you compile. Adding your own modules in there means that the code gets compiled into any program you make, even if it doesn't get used -- but it will increase the size of your executables.

Worse, if you have external dependencies (like your module requires a DLL for whatever), that requirement will then apply to any program you create.

To prevent your module from getting embedded, you'd need to make sure to use framework/import. (find FrameworkAssistant for a mostly automated process)

Oh, and something else to remember: most (all?) of the blitzmax updates/installs blow away all existing content from the pub.mod and brl.mod folders when you install -- so MAKE SURE YOU HAVE BACKUPS of your custom module elsewhere if you choose to install them in the those system folder, because they WILL disappear on you when you isntall an update.

Bottom line: you really shouldn't be using those two folders to store custom data. :-?


Brucey(Posted 2009) [#23]
blitzmax updates/installs blow away all existing content from the pub.mod and brl.mod folders

Yep... that's the important one.

Ideally, you do want to use Framework with a list of Imports. This will make your applications much smaller, since you only include what you are using.

But each to their own, of course :-)


B(Posted 2009) [#24]
ok thanks guys. i think ill just stick to putting import blah.mod at the beginning ofmy program. right by Superstrict! lol

I was having problems with one of my space game, so i decided to use superstrict, i wasnt using anything strict/super and it really helped me solve my problem! :P

my program was crashing in the middle of my game and the debug mode wasnt catching anything at all! i was really quite dumbfounded, but when I turned on superstrict, and went back through all of my variables to assign a type to them i found that I was just trying to access a null object as an image, i used the wrong name when referencing it.

YEY! to Superscript! (i still dont know why debugmode didnt pick it up)

anyways, I also used releasemode and the proper framework for my program and it cut the
size from 1.4 megs! to around 250 KB!

Wow!


well thanks again everyone for all the advice! :)

B


xlsior(Posted 2009) [#25]
No problem.

By the way: the link in your .sig isn't getting rendered properly.


B(Posted 2009) [#26]
ya i know and I have no idea what todo!
is it BBcode or html?

i have tried both and I dont know whats wrong


Brucey(Posted 2009) [#27]
By the way: the link in your .sig isn't getting rendered properly.

@B, see the "forum codes" link just above the posting text field for a link to a page which lists valid forum codes - (you want to use square instead of angle brackets and remove the href="... bit)


B(Posted 2009) [#28]
I tried the forums codes thing and it still hasnt worked :(


B(Posted 2009) [#29]
ok i got it. i didnt know that it was mandatory to use http:// in from of www.