ACS - Array Nightmare

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
Setzer
Posts: 124
Joined: Mon Mar 13, 2006 11:12 pm
Location: nowhereville

ACS - Array Nightmare

Post by Setzer »

I apologize in advance for such a huge pile of confusion, but I am stumped on this issue completely...

My problem? ACS doesn't allow for multi-dimensional arrays. Thanks to this, a strange system I've been working on is now in a state of panic. For you see, I cannot think of a simple way to achieve what I'm doing without this.

Basically, I have a three-dimensional array that contains data for several text-display terminals in the map. Each entry in the array has three levels: the terminal being accessed, what screen the terminal is displaying (hitting "use" cycles through the different screens on a single terminal), and the line of text being displayed. Yes, there is a reason for each line being defined seperately. Bear with me here.

The array setup I'd like to use would look something like this hacked sample:

Code: Select all

global str 1: termtext[][][];

termtext[0][0][0] = "Terminal 0, Screen 0, Line 0"
termtext[0][0][1] = "Terminal 0, Screen 0, Line 1"
termtext[0][0][2] = "Terminal 0, Screen 0, Line 2"

termtext[0][1][0] = "Terminal 0, Screen 1, Line 0"
termtext[0][1][1] = "Terminal 0, Screen 1, Line 1"
termtext[0][1][2] = "Terminal 0, Screen 1, Line 2"

termtext[1][0][0] = "Terminal 1, Screen 0, Line 0"
termtext[1][0][1] = "Terminal 1, Screen 0, Line 1"
termtext[1][0][2] = "Terminal 1, Screen 0, Line 2"

termtext[1][1][0] = "Terminal 1, Screen 1, Line 0"
termtext[1][1][1] = "Terminal 1, Screen 1, Line 1"
termtext[1][1][2] = "Terminal 1, Screen 1, Line 2"
...and so on and so forth. You get the drift.

Now, as you see, this would work flawlessly on a map scope, but my intention was to have the strings defined in a script library, to be accessed through any map at any time. And thus, my system cannot work because global variables don't support more than one dimension. I'm sure there's some type of strange technical limitation which prevents ZDoom from supporting such a feature, so I will instead take another route...

Can any kind soul provide me with a simple method to "simulate" such a system using only single-dimensional arrays? I'd hate to see this idea of mine go down the drain. If I can get this system working, the methods of implementing the screens in-map would be far simpler and not nearly so hellish to set up. However, that means I'd have to overcome this obstacle... how fitting.

Thanks for at least trying to make sense of this strange "request"...
User avatar
solarsnowfall
Posts: 1581
Joined: Thu Jun 30, 2005 1:44 am

Post by solarsnowfall »

For globals, you'd have to order them one by one.

Code: Select all

termtext[0] = "Terminal 0, Screen 0, Line 0"
termtext[1] = "Terminal 0, Screen 0, Line 1";
termtext[2] = "Terminal 0, Screen 0, Line 2";

termtext[3] = "Terminal 0, Screen 1, Line 0";
etc
Then you could assemble them into a map array like this if you must have a three dimensional structure.

Code: Select all

str m_termtext[2][2][3];

Script 1 OPEN
{
	for (int i1=0; i1<2; i1++)
		for (int i2=0; i2<2; i2++)
			for (int i3=0; i3<3; i3++)
				m_termtext[i1][i2][i3] = termtext[i1*6 + i2*3 + i3];
}
If you needed to store anything back into the global array...

Code: Select all

Script 2 (VOID)
{
	for (int i1=0; i1<2; i1++)
		for (int i2=0; i2<2; i2++)
			for (int i3=0; i3<3; i3++)
				termtext[i1*6 + i2*3 + i3] = m_termtext[i1][i2][i3];
}
that should work.

I sized the array based on what you listed in your example. Since there were two terminals the first size is 2, two screens so the second size is 2, and three lines, so the last size is 3. If you continue on in that pattern, you should just be able to increase the first size in the array and make sure you increase the value in your loop test expression (i1 < 2) in the first for loop to match, and you shouldn't need to change anything else. If you change the X by 2 by 3 pattern in the global array, this is how you get your multipliers, for the first one (i1 * x) multiply the second and third sizes, and the second mulitplyer (i2 * x) is the third size of the array.

Anyway, didn't you volunteer to help make sprites for a certain project? :roll:
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Post by Macil »

ACS does support multidimensional arrays, but apparently not as a global.

PS: Why not use code like
Print(s:"Terminal ", d:TerminalNum, s:", Screen ", d:ScreenNum, s:", Line ",d:LineNum);
where TerminalNum, ScreenNum, and LineNum are variables?
User avatar
solarsnowfall
Posts: 1581
Joined: Thu Jun 30, 2005 1:44 am

Post by solarsnowfall »

Agent ME wrote:ACS does support multidimensional arrays, but apparently not as a global.
Setzer wrote:Now, as you see, this would work flawlessly on a map scope
I'm pretty sure he understood that already. This is the case with any array above map scope.
User avatar
TheDarkArchon
Posts: 7656
Joined: Sat Aug 07, 2004 5:14 am
Location: Some cold place

Post by TheDarkArchon »

Agent ME wrote: PS: Why not use code like
Print(s:"Terminal ", d:TerminalNum, s:", Screen ", d:ScreenNum, s:", Line ",d:LineNum);
where TerminalNum, ScreenNum, and LineNum are variables?
Because I would say Setzer is planning to do a little bit more that just print out terminal names.
User avatar
Setzer
Posts: 124
Joined: Mon Mar 13, 2006 11:12 pm
Location: nowhereville

Post by Setzer »

Thank you for all your help, but as it always seems to work, a solution hit me shortly after creation of this thread. Solar's solution, while very ingenious, would have been difficult to manage due to my usage of very large amounts of data. I wound up instead using a row of switch statements to determine which terminal and screen are being accessed, and while it's a bit messier than I would have liked, it works admirably. Thanks again for trying to assist me anyhow, despite being left in the dark completely.

And I had intended to keep this secret, but I am starting a thread soon enough so I may as well reveal my purpose.
Image
Yes, this is a fully-working in-game shot. I still have a few kinks in the system but it turned out rather nice. Props to those individuals who recognize the source of "inspiration". No, I am not planning a direct remake, but I do have ideas. Great ones.
User avatar
Kirby
Posts: 2697
Joined: Thu Aug 26, 2004 1:23 pm

Post by Kirby »

Ohhh, pretty! :D
User avatar
Risen
Posts: 5263
Joined: Thu Jan 08, 2004 1:02 pm
Location: N44°30' W073°05'

Post by Risen »

Setzer wrote:Solar's solution, while very ingenious, would have been difficult to manage due to my usage of very large amounts of data.
It's not at all difficult to manage large amounts of data that way. I programmed a near identical system a few years back to handle the exact problem you're having now and it handles 1120 distinct values which are frequently updated. If required, it could quite easily scale to much more.
User avatar
Kristus
Posts: 437
Joined: Wed Feb 23, 2005 4:02 am
Location: Bed

Post by Kristus »

Setzer wrote:Yes, this is a fully-working in-game shot. I still have a few kinks in the system but it turned out rather nice. Props to those individuals who recognize the source of "inspiration". No, I am not planning a direct remake, but I do have ideas. Great ones.
It looks intresting. But, please fix the horrible dithering, jeez.
User avatar
Setzer
Posts: 124
Joined: Mon Mar 13, 2006 11:12 pm
Location: nowhereville

Post by Setzer »

Well, it is apparent you have never played Marathon, then. The demo screen is simply a direct rip from the game, pictures and text. The original image was subject to the same problems, so take it up with Bungie.
Before anyone asks, custom content is on the way, but I wanted to overcome the coding obstacles first before writing the project's terminal progression.

No need to be trashy.
Locked

Return to “Editing (Archive)”