Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rocco on Tue 14/11/2006 14:46:54

Title: initialize float
Post by: Rocco on Tue 14/11/2006 14:46:54
i want to initialize a var:

float radiance = ((startAngle-90.0) / 180.0) * Maths.Pi;

but get this error:
---------------------------
Compile Error
---------------------------
There was an error compiling your script. The problem was:

In: 'Drive Module'

Error (line 15): Expected floating point value after '='


is there a workaround?
Title: Re: initialize float
Post by: Gilbert on Tue 14/11/2006 14:56:21
What is startAngle? Was it a float variable or a float constant?

Also, where did you put that declaration?
If it's on top of script, outside of functions, it can't take variables in it (probably not even the Maths.Pi property), if you have to initialize it using such formula, etc. you may either 1) assign the value in game_start() (if it's in global script), or 2) assign the value in "player enters room (for the first time)" event (if it's in a room script).
Title: Re: initialize float
Post by: SSH on Tue 14/11/2006 14:58:35
Modules can also have their own game_start, in case this is in a module...
Title: Re: initialize float
Post by: Rocco on Tue 14/11/2006 15:48:51
yes its a module its on top of the script, and i have no problems initializing vars with values directly,
so

float startAngle = 0.0;Ã,  <- this works
float radiance = ((startAngle-90.0) / 180.0) * Maths.Pi; <- this not

it works, when i put this in game_start, but i need them in different functions in game,
(rep_execute)

and the first test with

function game_start ()
{
float maxspeed = 5.0;
float startAngle = 0.0;
float speed = 0.0;
float radiance = ((startAngle-90.0) / 180.0) * Maths.Pi;

export speed;
export maxspeed;
export radiance;
}

and imports in the header file
brings this error
---------------------------
Compile Error
---------------------------
There was an error compiling your script. The problem was:

In: 'Drive Module'



Error (line 6): Local variable cannot have the same name as an import


i try to build a bird eye view car- driving module,
, first tests with the Rotate Function didnt work.
now i want to try it with different pics for the directions, dont know if i can get it to work.
Title: Re: initialize float
Post by: Gilbert on Tue 14/11/2006 16:04:28
What's the real problem then? Just declare it on top of the script and assign its value in game_start():


float startAngle = 0.0;
float radiance = ((startAngle-90.0) / 180.0) * Maths.Pi;

it works, when i put this in game_start, but i need them in different functions in game,
(rep_execute)

and the first test with

function game_start ()
{
float maxspeed = 5.0;
float startAngle = 0.0;
float speed = 0.0;
float radiance = ((startAngle-90.0) / 180.0) * Maths.Pi;

export speed;
export maxspeed;
export radiance;
}

Title: Re: initialize float
Post by: SSH on Tue 14/11/2006 16:12:23
Not sure, but shouldn't the exports be outside the function?
Title: Re: initialize float
Post by: Khris on Tue 14/11/2006 17:15:54
float startAngle=0.0;Ã,  Ã, // left the =0.0 because you probably experiment with different values here
float speed;
float maxspeed = 5.0;
float radiance;
export speed;
export maxspeed;
export radiance;

function game_start () {
Ã,  radiance = ((startAngle-90.0) / 180.0) * Maths.Pi;Ã,  Ã,  // always 0.5*Maths.Pi unless startAngle is changed
}

Title: Re: initialize float
Post by: Rocco on Tue 14/11/2006 17:23:12
Quote from: Gilbot V7000a on Tue 14/11/2006 16:04:28
What's the real problem then? Just declare it on top of the script and assign its value in game_start():

ok, big thanks it works this way.