Home   Help Search Login Register  

Author Topic: Number to String Conversion...  (Read 652 times)

0 Members and 1 Guest are viewing this topic.

reedwasere

  • Guest
Number to String Conversion...
« on: 11 Dec 2004, 13:14:18 »
Hey everyone...

I wrote this script for an addon of mine - the Australian Defence Forces ARH Tiger



What it does is detects the Speed/Altitude of a helicopter and then changes the Heads up Display as needed.

Quote
_heli = _heli select 0

#loop

? ! isengineon _heli: goto "end"

_alt = getpos _heli select 1
_speed = speed _heli

? _alt > 9999 : _alt = ["e","e","e","e"], goto "next"
? _alt < 0 : _alt = [0,0,0.0], goto "next"

#next
? _speed > 9999 : _alt = ["e","e","e","e"], goto "display"
? _speed < 0 : _alt = [0,0,0,0], goto "display"

#display
_heli setobjecttexture [6, format ["\ADF_ARHtiger\hud\num%1.paa", _alt select 0]]
_heli setobjecttexture [7, format ["\ADF_ARHtiger\hud\num%1.paa", _alt select 1]]
_heli setobjecttexture [8, format ["\ADF_ARHtiger\hud\num%1.paa", _alt select 2]]
_heli setobjecttexture [9, format ["\ADF_ARHtiger\hud\num%1.paa", _alt select 3]]
_heli setobjecttexture [10, format ["\ADF_ARHtiger\hud\num%1.paa", _speed select 0]]
_heli setobjecttexture [11, format ["\ADF_ARHtiger\hud\num%1.paa", _speed select 1]]
_heli setobjecttexture [12, format ["\ADF_ARHtiger\hud\num%1.paa", _speed select 2]]-
_heli setobjecttexture [13, format ["\ADF_ARHtiger\hud\num%1.paa", _speed select 3]]
~0.5
goto "loop"

#end
_heli setobjecttexture [6, ""]
_heli setobjecttexture [7, ""]
_heli setobjecttexture [8, ""]
_heli setobjecttexture [9, ""]
_heli setobjecttexture [10, ""]
_heli setobjecttexture [11, ""]
_heli setobjecttexture [12, ""]
_heli setobjecttexture [13, ""]

exit

disregard the 'setobjecttexture' line it is of no importance to the problem.

basicly i have the altitude of the helicopter (stored as "_alt")
so lets assume...

Quote
_alt = 1234

now what i want to do is seperate _alt into it's digits for instance

Quote
_alt = [1,2,3,4]

like this, I can use a format command to select the digit I want and using that number I can run the setobjecttexture line.  (don't worry about how I do this, I understand it)

Quote
_heli setobjecttexture [6, format ["\ADF_ARHtiger\hud\num%1.paa", _alt select 0]]

so in simple words i want to know a method to select single digits out of a multiple digit number or convert a number to a string as I showed.

Number to String Conversion

but how the fornicate do I do it?  :P

Thanks for you help guys

Reed

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Number to String Conversion...
« Reply #1 on: 11 Dec 2004, 16:17:41 »
I haven't checked this or anything, I'll leave that to you.

Syntax is not quaranteed to be accurate, but is probably ok.

Code: [Select]
_altarr = []

(_altarr select 0) = ((_alt/1000)-(_alt mod 1000) ; _alt = _alt - ((_altarr select 0) * 1000)

(_altarr select 1) = ((_alt/100)-(_alt mod 100) ; _alt = _alt - ((_altarr select 1) * 100)

(_altarr select 2) = ((_alt/10)-(_alt mod 10) ; _alt = _alt - ((_altarr select 2) * 10)

(_altarr select 3) = _alt


hint format ["%1 - %2 - %3 - %4", altarr select 0, altarr select 1, altarr select 2, altarr select 3,]


The hint line is only there to check the 4 elements of the array come out ok.

Anyway, play with it until it works the way you want.

There is maybe a simpler way of doing this, but thats what I came up with, only took about 10 mins.   ::)

Planck
« Last Edit: 11 Dec 2004, 16:23:31 by Planck »
I know a little about a lot, and a lot about a little.

reedwasere

  • Guest
Re:Number to String Conversion...
« Reply #2 on: 11 Dec 2004, 23:57:15 »
thanks mate!!! you're a champion!

Offline CrashDome

  • Members
  • *
Re:Number to String Conversion...
« Reply #3 on: 12 Dec 2004, 00:07:40 »
Instead of:

(_altarr select 0) = .....
(_altarr select 1) = .....

It is better to use:

_altarr set [0, ..... ]
_altarr set [1, ..... ]

 ;)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Number to String Conversion...
« Reply #4 on: 12 Dec 2004, 11:05:04 »
Ok, time to 'pick a nit' ;D

Quote
It is better to use
How so?
Does exactly the same thing...

set is 'more pro'? ;) :P ;D
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

reedwasere

  • Guest
Re:Number to String Conversion...
« Reply #5 on: 12 Dec 2004, 13:13:59 »
I have worked it out!

I used a variation on what Planck posted...

Quote
_altarr = [0,0,0,0]
_altarr0 = 0
_altarr1 = 0
_altarr2 = 0
_altarr3 = 0

_altarr0 = (_alt / 1000) - (_alt mod 1000 / 1000)
_altarr set [0, _altarr0]

_altarr1 = (_alt / 100) - (_alt mod 100 / 100) - (10 * _altarr0)
_altarr set [1, _altarr1]

_altarr2 = (_alt / 10) - (_alt mod 10 / 10) - ((100 * _altarr0) + (10 * _altarr1))
_altarr set [2, _altarr2]

_altarr3 = _alt - ((1000 * _altarr0) + (100 * _altarr1) + (10 * _altarr2))
_altarr set [3, _altarr3]

_speedarr = [0,0,0,0]
_speedarr0 = 0
_speedarr1 = 0
_speedarr2 = 0
_speedarr3 = 0

_speedarr0 = (_speed / 1000) - (_speed mod 1000 / 1000)
_speedarr set [0, _speedarr0]

_speedarr1 = (_speed / 100) - (_speed mod 100 / 100) - (10 * _speedarr0)
_speedarr set [1, _speedarr1]

_speedarr2 = (_speed / 10) - (_speed mod 10 / 10) - ((100 * _speedarr0) + (10 * _speedarr1))
_speedarr set [2, _speedarr2]

_speedarr3 = _speed - ((1000 * _speedarr0) + (100 * _speedarr1) + (10 * _speedarr2))
_speedarr set [3, _speedarr3]

It's working  ;D ;D ;D

Thanks for all your help guys!

Offline CrashDome

  • Members
  • *
Re:Number to String Conversion...
« Reply #6 on: 17 Dec 2004, 08:38:13 »
Ok, time to 'pick a nit' ;DHow so?
Does exactly the same thing...

set is 'more pro'? ;) :P ;D

No, simply because that is what that command was designed for.