Record the levelnum of previous map?

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
User avatar
Jaxxoon R
Posts: 772
Joined: Sun May 04, 2014 7:22 pm

Record the levelnum of previous map?

Post by Jaxxoon R »

I'm trying to store the levelnum of the map the player warped from so I can return to it at a later date. I've put this down so far in an acs library:

Code: Select all

int thepreviousmapyouwarpedfrom;

int thepreviousmapxpos;
int thepreviousmapypos;
int thepreviousmapzpos;

Script "RingWarp" (VOID)
{
	Delay(8);
	FadeRange(255,230,200,0.0,255,255,255,1.0,35.0);
	thepreviousmapyouwarpedfrom = GetLevelInfo(LEVELINFO_LEVELNUM);
	Delay(35);
	Teleport_NewMap(100,0,0);
}

Script "ReturntoPreviousMap" (VOID)
{
	Teleport_NewMap(thepreviousmapyouwarpedfrom,0,0);
}
The issue is that the levelnum isn't properly stored, so the player is instead warped to The Earth Base every time.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: Record the levelnum of previous map?

Post by gwHero »

Try giving the variable world scope:

Code: Select all

world int thepreviousmapyouwarpedfrom; 
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Record the levelnum of previous map?

Post by Graf Zahl »

It needs to be global scope. World scope is per hub and will get lost as well.
User avatar
Jaxxoon R
Posts: 772
Joined: Sun May 04, 2014 7:22 pm

Re: Record the levelnum of previous map?

Post by Jaxxoon R »

Thanks for the help! It's reassuring to know this can be done. Unfortunately, I've never set up this kind of variable before. The compiler is telling me I'm missing an "index in world variable declaration", does this mean I have to create an array for it to work?
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: Record the levelnum of previous map?

Post by Blue Shadow »

Jaxxoon R wrote:Unfortunately, I've never set up this kind of variable before. The compiler is telling me I'm missing an "index in world variable declaration", does this mean I have to create an array for it to work?
[wiki=Scope]Time to learn, then[/wiki].
User avatar
Jaxxoon R
Posts: 772
Joined: Sun May 04, 2014 7:22 pm

Re: Record the levelnum of previous map?

Post by Jaxxoon R »

Huh, I spent about an hour searching the wiki yesterday and somehow didn't find that. Thanks for the help!
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Record the levelnum of previous map?

Post by Graf Zahl »

You would have found that page with both 'world variables' or 'global variables'.
User avatar
Jaxxoon R
Posts: 772
Joined: Sun May 04, 2014 7:22 pm

Re: Record the levelnum of previous map?

Post by Jaxxoon R »

I wouldn't be surprised if I was just dumb and didn't notice it then. Should stop modding late at night since it leads to silly mistakes like this.
Post Reply

Return to “Scripting”