Combining Array integers into one
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
- Theshooter7
- Posts: 456
- Joined: Sun Mar 05, 2006 6:44 pm
Combining Array integers into one
Is there a possible way to take to Array indexes, and combine them into a single integer? I do not mean adding them, but kinda like joining them.
Example:
Say Arrays[0] = 3 and Arrays[1] = 5. Is there a way to join them into 35?
Example:
Say Arrays[0] = 3 and Arrays[1] = 5. Is there a way to join them into 35?
I don't think so, I wanted to do something like this once and the best minds in the game couldn't help me. However, you might try something like:
Just multiply the respective variables by the appropriate power of 10 so that they're at the right decimal place and add everything together. Beyond that I don't think there's an answer for your problem. 
Code: Select all
int combined = Arrays[0]*10 + Arrays[1]- Theshooter7
- Posts: 456
- Joined: Sun Mar 05, 2006 6:44 pm
- chaoscentral
- Posts: 677
- Joined: Sun Feb 27, 2005 4:32 pm
- Location: Revere, MA
- Contact:
- Theshooter7
- Posts: 456
- Joined: Sun Mar 05, 2006 6:44 pm
I think this should work:
Code: Select all
int TestNumber[5] = {10, 100, 1000, 10000, 100000};
// I suggest that this could be a map array, and of course you can add more if needed
script xxx
{
int i, combined;
...
for(i = 0; Arrays[1] > TestNumber[i]; i++) {}
combined = Arrays[0] * TestNumber[i] + Arrays[1];
...
}
If all you want to do is print them right next to each other, ACS already has all the tools you need:
Other than that, I don't see why multiplying one number by 10 and adding them is such a big deal. Or if you want to do it carlcyber's way:
Code: Select all
print (i:Arrays[0], i:Arrays[1]);Code: Select all
int function stitchdigits (int left, int right)
{
for (int i = 10; i <= right; i *= 10) {}
return left * i + right;
}That might be simpler for you, but it would certainly involve more work by the VM and be slower.Nash wrote:This would be easy if string concatenation was supported.
Convert the arrays to strings and simply join them, then convert the joined string back to integer.
- Theshooter7
- Posts: 456
- Joined: Sun Mar 05, 2006 6:44 pm
