TGC Codebase Backup



Object Names instead of Object Numbers by Yukito

30th Sep 2003 12:44
Summary

Often I dont get though the tons of object-numbers... Maybe you too! Here is a simple way of using NAMES instead...



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    remstart

Often I dont get though the tons of object-numbers... Maybe you too!
Here is a simple way of using NAMES instead...

But dont forget to use this functions always in the project you used
them once, otherwise it may crash... :)

Functions provided:
 - CREATENAMEDOBJECT(NAME)
    Will create an entry in the database. Returns the number of the new object!
 - DELETENAMEDOBJECT(NAME)
    Will (let's guess) delete an entry in the database. Returns the number of the deleted object!
    It has to be combined with DELETE OBJECT!!! (Or just modify the function! But I didnt want it!)
 - NAMEDOBJECT(NAME)
    Returns the Number of the named object!
    You can use it with the most common functions!
 - NAMEDOBJECTEXIST(NAME)
    Returns 1 or 0
    I tried to make it with the common object exist() but it didnt work and I see no way of make it
    work... Use it INSTEAD of object exist()!!!!!

 So, here you go!

remend

global objdatabase
dim objdatabase(10000) as string

remstart ***************** HERE IS A SAMPLE FOR YOU! *******************

make object box createnamedobject("Box"),5,5,5

do
 if spacekey()=1 and namedobjectexist("Box")=1 then delete object deletenamedobject("Box")
 if leftkey()=1 and namedobjectexist("Box")=1 then yrotate object namedobject("Box"),object angle y(namedobject("Box"))-10
 sync
loop

remend : `*************** AND HERE THE FUNCTIONS! **********************

function createnamedobject(objname$)
 if objname$="" then exit prompt "Please use a name!","Error" : end
 for n=1 to 10000
  if object exist(n)=0 then objnr#=n : objdatabase(n)=objname$ : exit
 next n
endfunction objnr#

function deletenamedobject(objname$)
 if objname$="" then exit prompt "Please use a name!","Error" : end
 for n=1 to 10000
  if objdatabase(n)=objname$
   objdatabase(n)=""
   objnr#=n
   exit
  endif
 next n
endfunction objnr#

function namedobject(objname$)
 if objname$="" then exit prompt "Please use a name!","Error" : end
 for n=1 to 10000
  if objdatabase(n)=objname$
   objnr#=n
   exit
  endif
 next n
endfunction objnr#

function namedobjectexist(objname$)
 if objname$="" then exit prompt "Please use a name!","Error" : end
 output#=0
 for n=1 to 10000
  if objdatabase(n)=objname$
   output#=1
   exit
  endif
 next n
endfunction output#