<Cheesy advertising voice on> Hi, do you ever find yourself in that situation where your swamped with numbers of objects, images and sounds and just wish you could call them by a name rather than a number ?
Well now you can ! <Cheesy advertising voice off>
Ok enough of that, this is a simpel system that sacrifices a little speed for ease of programming.
To start with, include the routines in the codebox somewhere in your code.
The first step then is to put...
Gosub SetupMediaNaming
...somewhere at the beginning of your program.
then the system is ready. You can use the following commands
MakeObj(FileName$,name$)
Where 'FileName$' is the file path of the object
and Name$ is the name you would like to use instead of a number
You use all other object commands just like normal except you use a command and name rather than a number. eg:
MakeObj("Ball.x","Ball")
Position Object ObjNum("Ball"),10,0,20
MakeImg(FileName$,name$)
Where 'FileName$' is the file path of the image
Name$ is the name you would like to use instead of a number
and 'Tex' is the texture flag
as above you use a command instead of a number
MakeImg("TitleLogo.jpg","Logo",1)
Sprite 1,10,20,ImgNum("Logo")
The same method goes for sounds, except i have added a few more commands with sound. Not for a majorly important reason...i think i just fancied them at the time !
REM Project: CallMediaByName
REM Created: 15/05/2005 01:09:40
REM
REM ***** Main Source File *****
REM
SetupMediaNaming:
Type ObjectType
Name as string
Number as integer
Endtype
Type SoundType
Name as string
Number as integer
Endtype
Type ImageType
Name as string
Number as integer
Endtype
Dim Sounds(300) as Soundtype
Dim Images(300) as Imagetype
Dim Object(300) as ObjectType
return
Function MakeObj(FileName$,name$)
name$=lower$(Name$)
pos=Object(0).number
pos=pos+1
Filenam$=FileName$
Load Object Filenam$,pos
Object(pos).Name=Name$
Object(0).number=pos
endfunction
Function ObjNum(Name$)
name$=lower$(Name$)
for i=1 to Object(0).number
if Object(i).name=Name$
foun=i
endif
next i
endfunction foun
Function MakeImg(FileName$,name$,tex)
name$=lower$(Name$)
pos=Images(0).number
pos=pos+1
Filenam$=FileName$
Load Image Filenam$,pos,tex
Images(pos).Name=Name$
Images(0).number=pos
endfunction
Function ImgNum(Name$)
name$=lower$(Name$)
for i=1 to Images(0).number
if Images(i).name=Name$
foun=i
endif
next i
endfunction foun
Function MakeSnd(FileName$,name$)
name$=lower$(Name$)
pos=Sounds(0).number
pos=pos+1
Filenam$=FileName$
Load Sound Filenam$,pos
Sounds(pos).Name=Name$
Sounds(0).number=pos
endfunction
Function PlaySnd(Name$)
name$=lower$(Name$)
for i=1 to Sounds(0).number
if sounds(i).name=Name$
Play sound i
endif
next i
Endfunction
Function LoopSnd(Name$)
name$=lower$(Name$)
for i=1 to Sounds(0).number
if sounds(i).name=Name$
`Position Sound i,x#,y#,z#
Loop sound i
endif
next i
endfunction
Function StopSnd(Name$)
name$=lower$(Name$)
for i=1 to Sounds(0).number
if sounds(i).name=Name$
Stop sound i
endif
next i
endfunction
Function SndNum(Name$)
name$=lower$(Name$)
for i=1 to Sounds(0).number
if sounds(i).name=Name$
foun=i
endif
next i
endfunction foun
Function SndPlaying(Name$)
name$=lower$(Name$)
for i=1 to Sounds(0).number
if sounds(i).name=Name$
foun=i
endif
next i
if sound playing(foun)=1 then res=1
endfunction res
Hope someone finds this useful
Enjoy !
p.s. Any problems, bugs, criticism, compliments....just post !