[SOLVED] [ACS] Turning array-based map code into a library?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
violgamba
Posts: 29
Joined: Wed Apr 10, 2024 4:53 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10

[SOLVED] [ACS] Turning array-based map code into a library?

Post by violgamba »

So, I do have a solution to this problem, but it's not great. I wonder if anyone can think of a better one.

I have an ACS system for my map to print one of many predefined messages. All the messages are stored in an array, and there's a script to display a message which takes an index to this array. This works fine, but I'd like to make this system common to multiple maps, so I'm trying to move the system into a library in the pk3 file. I've successfully moved other code into libraries, but this is the first one where the code depends on an array who's values must be set per-map.

The library code won't compile without a declaration of the array. This declaration is, ideally, in the map code, but the compiler can't see that. In C, I could use "extern" to tell the compiler that the declaration exists elsewhere, but this isn't available in ACS. Instead, the only solution apparent to me is to pre-define the array to, like, 99 empty strings, then fill the array from the map script when the map loads.

So, I am considering how to fill the array from the map script. Passing an array into a function isn't possible, so only I'm reduced to making a function that sets a single value for the library. Then I need to iterate over all messages for the map and call the function for each of them.

This is also doable, but not great. Also, my description of the system is a simplification. In fact, I have 4 separate arrays to hold different data points about each message.

So, can anyone think of a better solution to a library that relies on map-specific data other than the one I've come up with?

Thanks for sharing any thoughts you have.
Last edited by violgamba on Tue Apr 23, 2024 10:21 pm, edited 1 time in total.
violgamba
Posts: 29
Joined: Wed Apr 10, 2024 4:53 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10

Re: [ACS] Turning array-based map code into a library?

Post by violgamba »

I ended up including the code instead of importing it as a library. It's still available to all maps, but now I can define the arrays in the map code. It'd still be nice to make a proper library for this, but #include works.
Post Reply

Return to “Scripting”