Home   Help Search Login Register  

Author Topic: DCV_NumToArray  (Read 1999 times)

0 Members and 1 Guest are viewing this topic.

Offline ModestNovice

  • Members
  • *
DCV_NumToArray
« on: 03 Apr 2009, 03:04:34 »
Hello I wanted to share with you a small code I did to convert a number to an array form.

Use Spooners.
« Last Edit: 04 Apr 2009, 04:18:18 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: DCV_NumToArray
« Reply #1 on: 03 Apr 2009, 03:34:41 »
Unfortunately, there has been a misunderstanding on how the OFPEC tag should be used. You only ever need, and in fact should always use, the tag for global variables. For local variables, the tag is redundant and does not act as a replacement for correct use of private (using the tag in a local does not prevent overwriting local variables in an outer scope!). Private has been used for _DCV_ret correctly, but not for all other local variables; private is required for all local variables, not just the value you will return. Here is a simplified (and safe) version:
Code: [Select]
private ["_number", "_digits"];

_number = toArray str floor _this;

_digits = [];

{
_digits set [count _digits, _x - 48];
} forEach _number;

_digits;
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline ModestNovice

  • Members
  • *
Re: DCV_NumToArray
« Reply #2 on: 03 Apr 2009, 03:38:07 »
ah ok. Its only in my tag as for its in my mission and just copied and pasted over. Sorry Spooner.

Grrr, Im mad at myself for not knowing this  :no:

Most ridiculously using call compile format to convert to a string.

Thanks Spoon.
« Last Edit: 03 Apr 2009, 03:41:50 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley