initialize float

Started by Rocco, Tue 14/11/2006 14:46:54

Previous topic - Next topic

Rocco

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?

Gilbert

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).

SSH

Modules can also have their own game_start, in case this is in a module...
12

Rocco

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.

Gilbert

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;
}


SSH

Not sure, but shouldn't the exports be outside the function?
12

Khris

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
}
Code: ags



Rocco

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.

SMF spam blocked by CleanTalk