Posted: 26th Jun 2007 2:20
can someone tell me why this code will not compile, it sais the object does not exist, what is the work around for this?

+ Code Snippet
sync rate 60.5

item_health(2,0,0,0)

do
gosub item_health_init
sync
loop

function item_health(ih_n,ih_x,ih_y,ih_z)
    make object box ih_n,5,12,5
    position object ih_n,ih_x,ih_y,ih_z
endfunction

item_health_init;
ih_s#=ih_s#+0.5
if ih_s#=355 then ih_s#=0
yrotate object ih_n,ih_s#
return
Posted: 26th Jun 2007 2:31
the sync rate should really be a integer or a whole number and not a float or decimal point number.

your variable declaration is correct but a little hard to read.

Think about making the variable names easier to read for your own sanity.

the gosub declaration should be a : and not a ;

the variables inside the function are currently local to that function area only, unless you declared them as global.

you should really keep practicing the basics so you understand these concepts before embarking on a larger amount of code.

If your going to make a game with many instances of the same object, you should explore types with arrays.


+ Code Snippet
REM MADE THIS AN INTEGER
sync rate 60
sync on

item_health(2,0,0,0)

do
gosub item_health_init
sync
loop

function item_health(ih_n,ih_x,ih_y,ih_z)
    make object box ih_n,5,12,5
    position object ih_n,ih_x,ih_y,ih_z
endfunction

REM CHANGED THE COLON
item_health_init:
ih_s#=ih_s#+0.5
if ih_s#=355 then ih_s#=0
REM INSERTED THE SAME NUMBER USED ABOVE IN YOUR FUNCTION
yrotate object 2,ih_s#
return
Posted: 26th Jun 2007 2:54
thanx, i 4got weather it was a colon or semi colon,lol

the problem with

REM INSERTED THE SAME NUMBER USED ABOVE IN YOUR FUNCTION
yrotate object 2,ih_s#

is that this file will be added into a main source file later on, and i don't want to be adding yrotate object for every instance of the object
Posted: 26th Jun 2007 3:57
you will have to forgoe a gosub and use a function
or deploy a global variable etc.

I would look at types and arrays before you get into it.

Imagine dealing with 50 health potions in your game and being able to reference them as Potion(1).X Potion(1).Health etc