Retrieving current map lump name (string) in ACS?

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.

Retrieving current map lump name (string) in ACS?

Postby Nash » Wed Nov 30, 2011 10:13 am

I'm pretty sure I've seen someone post an example before, but I can't remember it, and searching the forums and the wiki didn't reveal anything... is this possible, or am I just imagining it? This is killing me! D:

(I am looking into creating conditions if the current map lump is "TITLEMAP", "MAP05", "CINEMAP", etc)
User avatar
Nash
AKA Nash Muhandes! Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: Retrieving current map lump name (string) in ACS?

Postby Deathmatcher » Wed Nov 30, 2011 11:39 am

Shouldn't you just know which map you are currently scripting for? ;)
Or are working on some generalized scripts?
User avatar
Deathmatcher
 
Joined: 11 Dec 2003

Re: Retrieving current map lump name (string) in ACS?

Postby Nash » Wed Nov 30, 2011 11:40 am

If it was that simple, I wouldn't have had a need for this. :) There's some really complex globally autoloaded library magic going on.
User avatar
Nash
AKA Nash Muhandes! Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: Retrieving current map lump name (string) in ACS?

Postby FDARI » Wed Nov 30, 2011 12:22 pm

I think you can get the map number, but I don't think you can get the map name. That string isn't part of the compiled script, and therefore does not exist in ACS.

Here's my recommendation:
Code: Select allExpand view
#library "lib"

#libdefine SCRIPT_MAP_INIT 100 // USE ANY NUMBER
#libdefine MI_FLAG_NON0 0x80000000

int mi_flags; // start at 0, make sure it is non-0 when init is complete
str mi_mapname; // map name

script 200 open
{
    ACS_ExecuteWithResult(SCRIPT_MAP_INIT);
}
Code: Select allExpand view
#import "lib.acs"

// MAKE THIS SCRIPT IN EVERY MAP

script SCRIPT_MAP_INIT(void)
{
    if (mi_flags) terminate;

    mi_mapname = "Demon's maw";
    mi_flags |= MI_FLAG_NON0; // just to make sure it will always be true
}
If you don't need any additional flags ever, you can use mi_flags as a plain boolean. The example above contains only boolean functionality. You call ACS_ExecuteWithResult(SCRIPT_MAP_INIT) from at least one script (in library) during the first tick, and you call at the beginning of all ENTER/OPEN scripts that depend on its values (during the first tick).
User avatar
FDARI
Melbourne is actually pronounced Mel-Byn, as though it were a wizard.
 
Joined: 03 Nov 2009

Re: Retrieving current map lump name (string) in ACS?

Postby Worst » Wed Nov 30, 2011 7:06 pm

According to the wiki, using Print(n:-2) prints the map lump name. So if you'd use Strparam, you could check it with a function like:
Code: Select allExpand view
function bool CheckMapLump(str maplump)
{
  int strIndex = strparam(n:-2);
  return str_equal(maplump, strIndex);
}
Assuming that the string table never has duplicates, that should work. EDIT: Adjusted to use str_equal from FDARI in the post below.

Code: Select allExpand view
if (CheckMapLump("MAP01"))
{
..code..
}
Last edited by Worst on Thu Dec 01, 2011 6:11 am, edited 1 time in total.
Worst
 
Joined: 28 Apr 2007
Location: finland

Re: Retrieving current map lump name (string) in ACS?

Postby Nash » Wed Nov 30, 2011 7:37 pm

Well, it seems there's no other way than to utilize a map's levelnum (I'll have to assign every map a levelnum) and just use what I have available from GetLevelInfo...

EDIT: delay ninja'd by Worst.

Thanks!
User avatar
Nash
AKA Nash Muhandes! Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: Retrieving current map lump name (string) in ACS?

Postby FDARI » Thu Dec 01, 2011 2:27 am

Warning: While integer equality (maplump == strIndex) guarantees string equality (because they're exactly the same value), the return value from strParam is never equal to any predefined string index. To compare strings reliably you will require a helper function (or you must put a lot of code somewhere).
Spoiler: str_equal
Spoiler: str_compare
The above is untested but reasonably manageable code.

However, if you're only trying to identify the level, strings are not a shortcut. I'd just define/libdefine LEVEL_<name> <number> and check that. Much cheaper than the above hassle. Also, a bundle of defines can be used in a switch/case-statement as well as an if-statement.

...Like (very brief quasi-code)...
switch (getLevelInfo....)
{
case LEVEL_COMPLEX:
... code ...
break;
case LEVEL_DEIMOS_PORT:
... code ...
break;
}
User avatar
FDARI
Melbourne is actually pronounced Mel-Byn, as though it were a wizard.
 
Joined: 03 Nov 2009


Return to Editing (Archive)

Who is online

Users browsing this forum: No registered users and 3 guests