Combining Array integers into one

Archive of the old editing forum
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.
Locked
User avatar
Theshooter7
Posts: 456
Joined: Sun Mar 05, 2006 6:44 pm

Combining Array integers into one

Post by Theshooter7 »

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?
User avatar
Sir_Alien
Posts: 863
Joined: Sun Aug 29, 2004 6:15 am
Location: Sydney, Australia
Contact:

Post by Sir_Alien »

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:

Code: Select all

int combined = Arrays[0]*10 + Arrays[1]
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. :|
User avatar
Theshooter7
Posts: 456
Joined: Sun Mar 05, 2006 6:44 pm

Post by Theshooter7 »

Well, that may work. All I need it for is for a buy menu. You will be allowed to enter how much of an ammo type you want, rather than adding a ton of seperate options for diffrent amounts.
User avatar
chaoscentral
Posts: 677
Joined: Sun Feb 27, 2005 4:32 pm
Location: Revere, MA
Contact:

Post by chaoscentral »

if its for a buy menu, make it CS style, where you get 1 clip for so much money, and allow them to keep buying until they run out of money, or the clip is full, which ever is first
User avatar
Sir_Alien
Posts: 863
Joined: Sun Aug 29, 2004 6:15 am
Location: Sydney, Australia
Contact:

Post by Sir_Alien »

Isn't that just Strife style?
User avatar
Theshooter7
Posts: 456
Joined: Sun Mar 05, 2006 6:44 pm

Post by Theshooter7 »

I have another question. (Rather than starting another thread.)

How does GiveInventory/TakeInventory and Get/SetAmmoCapacity work online? Does it affect everyone, or just the activator(s)?
User avatar
Sir_Alien
Posts: 863
Joined: Sun Aug 29, 2004 6:15 am
Location: Sydney, Australia
Contact:

Post by Sir_Alien »

Just the activator.
carlcyber
Posts: 163
Joined: Thu Jan 27, 2005 1:04 am

Post by carlcyber »

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];
	...
}
User avatar
Nash
 
 
Posts: 17505
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Post by Nash »

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. =D
User avatar
Medricel
Posts: 1138
Joined: Sat Nov 20, 2004 9:47 am

Post by Medricel »

but I thought using a string as an integer would return the strings index as an integer, not its numerical value. *scratches head*
User avatar
Nash
 
 
Posts: 17505
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Post by Nash »

Nash wrote:if string concatenation was supported.
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Post by randi »

If all you want to do is print them right next to each other, ACS already has all the tools you need:

Code: Select all

print (i:Arrays[0], i:Arrays[1]);
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

int function stitchdigits (int left, int right)
{
    for (int i = 10; i <= right; i *= 10) {}
    return left * i + right;
}
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.
That might be simpler for you, but it would certainly involve more work by the VM and be slower.
User avatar
Theshooter7
Posts: 456
Joined: Sun Mar 05, 2006 6:44 pm

Post by Theshooter7 »

Well, I do need them in HudMessages and in some other stuff. These methods work. Thanks guys.
Locked

Return to “Editing (Archive)”