[ZScript] Status Bar questions (and memory bug?)

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.

[ZScript] Status Bar questions (and memory bug?)

Postby Virathas » Thu Jan 07, 2021 4:29 am

Hey,

I have started work on converting my unwieldy SBARINFO status bars into the new reliable ZScript class. However, i do have some questions about that:

1. Is it possible to give separate Status bars to various player classes? Currentl I've created an enormous class with "if (CPlayer.mo is <PlayerClass>)" for each class.

2. Is conversion string to inventory still unavailable? I've looked through the forums but i have not found if it changed. This would be handy (and probably clear some memory):
Spoiler:

Right now i use "Static const Inventory", but these leads to following problem:

3. Is there a limit to the amount of "Static const" declared values? With enough of such arrays, any operation on an array with Inventory class type inside a "for" loop caused the iteration index to change, causing nearly immediate VM crash due to "index out of bounds". As a simple loop is not enough to cause the issue i have attached a full statusbar here:
Spoiler:

Running this status bar will immediately cause the VM to crash. However, commenting out some of these declared constants, will cause the script to work properly. (This status bar is not my actual status bar, but uses close to the quantity of static declarations as i use currently (and i planned to use several more). (I also have a very dirty workaround for this problem, but like all other problems with memory, it can run deeper.)

4. Is there any benefit to use
Code: Select allExpand view
int amt;
amt = GetAmount("Item");
if (amt > 0)
{
 <code>
}

instead of
Code: Select allExpand view
if (GetAmount("Item") > 0)
{
 <code>
}
User avatar
Virathas
 
Joined: 10 Aug 2017

Re: [ZScript] Status Bar questions (and memory bug?)

Postby Cherno » Thu Jan 07, 2021 4:53 am

1.
No, but you could "outsource" code blocks that are shared between different class-specific statusbar styles into functions, so you'd only have to call these functions for each class instead of having to repeat all kinds of lines for drawing text and images for the classes.

2.
Try
Code: Select allExpand view
static const String ItemClasses[]
{
"Item0",
"Item1",
"Item2",
"Item3",
"Item4",
"Item5"
}
for (int i = 0; i < 5; ++i)
{
class<Inventory> invClass= ItemClasses[i];
if (invClass && CheckInventory(invClass))
{
 <Code>
}
}


4.

No, as long as you don't need to access the return value further down below.
User avatar
Cherno
 
Joined: 06 Dec 2016


Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests