Register Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
techbear

Administrator
Registered:
Posts: 110
Reply with quote  #1 
Hi guys.  I'm working on the scripting, and other things, for Armada 3.  And in my discussions with Mike S, and direct examination of the code and my scripting docs,  I've realized something.

Script variables are INTEGERS, not floating point.  This is presented in a very confusing way, for a lot of reasons. Object_properties are floats, and are very clearly defined as such.  But "set_variable" and "if_variable" deal in integers.  I've realized that I've done a disservice to variables.


I don't want to break everybody's scripts, but I want to fix this.  Specifically, I want to change all script variables to floats.  I ALSO want to add an attribute to "set_variable" that would force the individual variable to be an integer.

What do YOU think?  What would be most helpful, and least disruptive?



Fish Evans

Registered:
Posts: 347
Reply with quote  #2 
well whilst 1 and 1.0 are differnt bitwise... the math functions would still create the same expected results ie 1+1=2 vs 1.0 + 1.0 = 2.0 - as long as we dont try mixing Integers and floats rigth? so as long as the script treats everything as floats... I cant see massive amounts of breakage im no expert at theses things im afraid though.

if you are alooking at variables is there the posibility you could let us copy propertys to a variable? it would be helpful to simulate say minelaying activity.
MarkBell

Avatar / Picture

Administrator
Registered:
Posts: 1,610
Reply with quote  #3 
I think if everything becomes a float, then it should be OK. The only thing that might get tricky is specific integer relations like fleet number, player slot, etc. I don't know if those count as variables or not, but it's a thought.
__________________
Note - this is in no way intended to be an official position of Thom or Artemis, as I am not an official representative of the creator or game.
Xavier Wise

Registered:
Posts: 978
Reply with quote  #4 
This would make things so much easier!

One way I use variables in my scripts is to set properties of objects, like ship angles (measured in radians), and have had real issues with the variable only being integers. The fix I use is to recall the variable and divide by 10 or 100. 

For example: 

Code:
<set_variable name="Artemis_Angle" value="105.0" />


Code:

<set_object_property property="angle" value="Artemis_Angle/100" name="Artemis" />


I also wanted to use them for a timer, but again had to use whole numbers, divided by 10/100/1000. 

Being able to set them straight away as float values would make it so much easier and quicker. 

__________________
Captain Xavier Wise TSN Raven (BC-014)
Link to TSN RP Community website
Link to TSN Sandbox
Link to Blog
CattailNu

Registered:
Posts: 62
Reply with quote  #5 
If comparisons are done with static precision, that would work.  1 = 1.0, because the actual check is doing 1.0000 = 1.0000.

Debugging scripts would get much easier with an optional variable in the log statement:
<log text="Starting\n"/>
to
<log text="Starting\n" name="variable_is_launched" />

Output from:
Starting

To:
Starting
variable_is_launched = 0.0000
ryleyra

Registered:
Posts: 2,408
Reply with quote  #6 
I would say it depends on if you want to do type checking or not. If you don't, then making everything a float is probably the best solution. If you do, you can define set_float and if_float and the existing scripts wouldn't be effected.

Personally, ever since I realized that randomFloatHigh and randomFloatLow were generating integer variables, not floats, I've wondered why that feature is there. It is true that randomInt is limited to a range of x to x+32768, and randomFloat isn't, but you could eliminate randomInt and use randomFloat.

Don't forget that your F7 debug screen also displays both variables and object properties as integers.
LawsonThompson

Registered:
Posts: 351
Reply with quote  #7 
Quote:
Originally Posted by techbear
...
I don't want to break everybody's scripts, but I want to fix this.  Specifically, I want to change all script variables to floats.  I ALSO want to add an attribute to "set_variable" that would force the individual variable to be an integer.

What do YOU think?  What would be most helpful, and least disruptive?


Regarding the set_variable attribute (force_int=true perhaps?): would this round, or truncate?

__________________
----
Visit us at http://www.ltebridge.com
ryleyra

Registered:
Posts: 2,408
Reply with quote  #8 
Quote:
Originally Posted by LawsonThompson

Regarding the set_variable attribute (force_int=true perhaps?): would this round, or truncate?


Well, if it works as current, it should truncate. The option to round to the nearest int might be a good idea, though. Maybe "force_int=true" for truncate and "force_int=round" for rounding. Or any non-"round" value for truncate, so you could use "force_int=yes". (Consistent with use_gm_selection)

Mike Substelny

Avatar / Picture

Administrator
Registered:
Posts: 1,658
Reply with quote  #9 
Quote:
Originally Posted by LawsonThompson


Regarding the set_variable attribute (force_int=true perhaps?): would this round, or truncate?


If it truncates you could probably write math to round when rounding is desirable. Just add 0.5 to the float value before assigning it to the integer variable.

I would say the best practice would be to declare force_int statements in the start block. But based on the way the code has always worked it will probably be possible to put a force_int anywhere in your code. This could lead to strange results and make debugging a science fiction adventure all its own!

__________________
"The Admiralty had demanded six ships; the economists offered four; and we finally compromised on eight."
- Winston Churchill
Previous Topic | Next Topic
Print
Reply

Quick Navigation: