lots of functions with descriptions, from my work on my
7drl (seven day roguelike)
(according to top post, there are over 200 functions. i tried downloading and found only about 20-50. so please forgive me if some of this work has been duplicated. that is not my intention)
this function is used for reading text lines from data files, specifically ones with 'line headers'
if your monster data was in file # 1, and if this was the data in the file:
MonsterStrength : 10
you would want to cut off the first 18 characters to get your value, so
ReadFileItem(1,18)
it also allows lines that start with ` to be not read, so you can put other information in your data files.
the actual return type is String, so you'd want val(readfileitem(1,18))
Function ReadFileItem(f,x)
` f is the file # to read
` lines that start with the rem character "`" are IGNORED
` L is the LENGTH of the "HEADER" to remove from the file.
if f>0
repeat
a$=ReadLine(f)
until left(a$,1)<>"`" : ` or FileEOF(f)
endif
if x>0
L=len(a$)
a$=right(a$,L-x)
endif
Endfunction a$
this function will make sure that a particular value remains between 2 values.
x=bind(x,1,10)
x will always be between 1 and 10
Function Bind(x,lo,hi)
if x<lo then x=lo
if x>hi then x=hi
Endfunction x
this will add zeroes to the beginning of a score (like if you want your score to be 6 digits,
and it's only 123, do score$=pad(str(score),"0",6). this will insert 0's at the beginning.
it can add any string (b$) to any length(p) to any string (a$).
Function Pad(a$,b$,p)
` this version of PAD() can put any string at the front of another,
` to make it of a certain length. useful to add spaces or ZERO's.
while len(a$)<p
a$=b$+a$
endwhile
Endfunction a$
compilation sprite code. index number, image #, x,y,depth
has several checks to stop failures/crashes
Function Sprite(n,i,x,y,d)
` number, image, x&y, DEPTH.
` DEPTH: default=10, 1 is CLOSEST, 10000=furthest away.
` setting dungeon to 10, treasures to 9 and monsters to 8 and PLAYER to 1 should cover it.
if getspriteexists(n)=0
if i>0
if getimageexists(i)=1
createsprite(n,i)
setspriteposition(n,x,y)
if d>0
setspritedepth(n,d)
endif
endif
endif
endif
Endfunction
a text compilation function.
id#,string,x,y,size,alignment
Function Text(n,a$,x,y,z,alig)
` number, name, x/y, size, alignment (0,1,2)
` returns a 1 if successful.
if z<10 or z>72 then z=16
sxs=1
if gettextexists(n)=0
createtext(n,a$)
settextsize(n,z)
settextalignment(n,alig)
settextposition(n,x,y)
else
sxs=0
endif
Endfunction sxs
checks a range of sprite numbers to see if the pointer is above them
it does not actually detect the 'press' event, but it will return the
sprite number that the pointer is over, if between the ranges 'lo' and 'hi'
Function DetectSprite(lo,hi)
` this function will see if you are clicking a sprite
` between the numbers given.
S=0
x=getpointerx()
y=getpointery()
for t=lo to hi
If GetSpriteExists(t)
h=getspriteheight(t)
w=getspritewidth(t)
a=getspritex(t)
b=getspritey(t)
if x<(a+w) and x>a
if y<(b+h) and y>b
S=t
EXIT
endif
endif
Endif
next t
Endfunction S
this functions takes a number and returns it as a string with commas 1656323 comes back as 1,656,323.
Function Commify(x)
a$=str(x)
b$=""
L=len(a$)
for t=1 to L
if t>1 and (t mod 3 = 1)
b$=","+b$
endif
b$=mid(a$,(l-t)+1,1)+b$
next t
Endfunction b$
this function deletes sprites betweeen the id range 'a'-'b'.
it checks to see if they exist first, so it's safe.
Function DeleteSprites(a,b)
for t=a to b
if getspriteexists(t)
deletesprite(t)
endif
next t
Endfunction
deletes a range of text IDs, a-b,but only if they exist.
Function DeleteTexts(a,b)
for t=a to b
if gettextexists(t)
deletetext(t)
endif
next t
Endfunction
this sets a range of text strings a-b to null ""
if you want to clear your displays without deleting them
Function ClearTex(a,b)
for t=a to b
if gettextexists(t)
settextstring(t,"")
endif
next t
Endfunction
if you use a lot of keypresses, this function might help avoid unintentional chains of the same key
it works by ascii value. if the player presses Q, call WaitForUnPress(81)
and the system will hold until the key is released. from what i found, sync is necessary to detect releases.
Function WaitForUnPress(x)
repeat
sync()
until getrawkeystate(x)=0 or getrawkeyreleased(x)=1
Endfunction
this is a D&D inspired function. it rolls a y-sided die x # of times, and returns the value.
xdy(3,6) returns a value between 3-18. xdy(2,20) yields 2-40.
Function xdy(dice,die)
a=0
for t=1 to dice
a=a+random(1,die)
next t
Endfunction a
this sets a large number of sprites (L-H) either visible(1) or invisible(0)
Function ssv(l,h,v)
` massive SetSpriteVisible()
for t=l to h
if getspriteexists(t)
setspritevisible(t,v)
endif
next t
Endfunction