[ZSCRIPT] Mikk's Dumb Questions

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
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

[ZSCRIPT] Mikk's Dumb Questions

Post by Mikk- »

Hi! I've encountered a slight problem with something I'm working on, I've noticed that upon death ZScript Variables defined on a player are reset upon respawn. Is there any way to solve this? Or do I have to revert to Global variables...

Say for example my player has one 1D array and one variable defined, these are read and manipulated by ACS' [wiki]GetUserVariable[/wiki] & [wiki]SetUserVariable[/wiki]. In this case, the player can rest at a certain points in a level (in a hub, I should add), the current levelnum and id of the rest point are stored in the player's lastbonfire array, however, these variables are cleared upon respawn which makes this system arguably useless...
Last edited by Mikk- on Fri Dec 15, 2017 5:09 pm, edited 1 time in total.
User avatar
AFADoomer
Posts: 1322
Joined: Tue Jul 15, 2003 4:18 pm
Contact:

Re: [ZSCRIPT] Variables reset upon respawn

Post by AFADoomer »

Possibly dumb question: Is the player actually respawning (as you would in DM/Coop), or is the game restoring from the autosave that gets generated when you start a level?
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

Re: [ZSCRIPT] Variables reset upon respawn

Post by Mikk- »

The player is actually respawning, the maps have allowrespawn enabled in MAPINFO
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZSCRIPT] Variables reset upon respawn

Post by Graf Zahl »

The player which respawns is a completely new actor which will not get the values of the previous version transferred to it.
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

Re: [ZSCRIPT] Variables reset upon respawn

Post by Mikk- »

Graf Zahl wrote:The player which respawns is a completely new actor which will not get the values of the previous version transferred to it.
Ah, I was worried it was as such. Is there any workaround, or some such way to transfer the values to the newly spawned player actor?
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [ZSCRIPT] Variables reset upon respawn

Post by Nash »

Would storing the variables on an undepletable inventory inside the player work?
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

Re: [ZSCRIPT] Variables reset upon respawn

Post by Mikk- »

That sounds like it could work, but I don't really know how to store and access variables on an inventory item - ZScript is all so very new and confusing to me! :oops:
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [ZSCRIPT] Variables reset upon respawn

Post by Nash »

Try this.
Attachments
player variable.pk3
(3.53 KiB) Downloaded 69 times
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

Re: [ZSCRIPT] Variables reset upon respawn

Post by Mikk- »

Brilliant! thanks Nash! Now I've hit another roadblock... How can I access these variables through an Event Handler? Specifically PlayerEntered, PlayerDied and PlayerRespawned. Event handlers are like black magic.

So far I have:

Code: Select all

class Souls_Player : ClericPlayer
    {
    default
        {
        Player.StartItem "Souls_BonfireInfo";
        }
    }

class Souls_BonfireInfo : Inventory
{
    int souls_lastbonfire[2];
    int souls_returning;

    Default
    {
        Inventory.MaxAmount 1;
        +INVENTORY.UNDROPPABLE;
        +INVENTORY.HUBPOWER;
        +INVENTORY.UNTOSSABLE;
    }
}

// Very basic and non-functional event handler 
// l o l 
class Souls_Handler : EventHandler
    {
    override void PlayerEntered(PlayerEvent e)
        {
        if(e.IsReturn)
            {
            }
        }
    override void PlayerDied(PlayerEvent e)
        {
        }
    Override void PlayerRespawned(PlayerEvent e)
        {
        }
    } 
What I want this handler to do is:

Code: Select all

    1. Upon death, set player "Souls_Returning" to true
    2. Upon Respawn, Teleport_NewMap to "Souls_LastBonfire[1]"
    3. Upon Entry (& e.IsReturn) to clear the Souls_Returning value
    4. Teleport the player to "Souls_LastBonfire[0]"
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [ZSCRIPT] Variables reset upon respawn

Post by Nash »

Hey sorry for the late reply. Here I show you how to access your variables from an Event Handler.
Attachments
player variable 2.pk3
(3.95 KiB) Downloaded 75 times
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

Re: [ZSCRIPT] Variables reset upon respawn

Post by Mikk- »

Thank you so so much Nash! This will help me immensely! Regarding your challenge, I think I've come up with a neat solution (I think) :P

Code: Select all

class Souls_Player : ClericPlayer
    {
    default
        {
        Player.StartItem "Souls_PlayerInfo";
        }
        
    int GetSoulInfo(int variable)
        {
        let pVar = Souls_PlayerInfo(FindInventory("Souls_PlayerInfo"));

        if (pVar)
            {
            switch(variable)
                {
                case LAST_BONFIRE_NUM:
                    return pVar.souls_lastbonfire[0];
                    
                case LAST_BONFIRE_MAP:
                    return pVar.souls_lastbonfire[1];
                    
                case PLAYER_RETURNING: 
                    return pVar.souls_returning;
                
                }
            }
        return 0;
        }
    
    void SetSoulInfo(int variable, int amount)
        {
        let pVar = Souls_PlayerInfo(FindInventory("Souls_PlayerInfo"));

        if (pVar)
            {
            switch(variable)
                {        
                case LAST_BONFIRE_NUM:
                    pVar.souls_lastbonfire[0] = amount;
                    break;
                    
                case LAST_BONFIRE_MAP:
                    pVar.souls_lastbonfire[1] = amount;
                    break;
                    
                case PLAYER_RETURNING: 
                    pVar.souls_returning = amount;
                    break;
                    
                }
            }
        }
    }

class Souls_PlayerInfo : Inventory
{
    int souls_lastbonfire[2];
    int souls_returning;

    Default
    {
        Inventory.MaxAmount 1;
        +INVENTORY.UNDROPPABLE;
        +INVENTORY.HUBPOWER;
        +INVENTORY.UNTOSSABLE;
    }
}
 
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [ZSCRIPT] Variables reset upon respawn

Post by Nash »

Good job! Hope you have fun learning ZScript. It's not as scary as some people make it out to be. :D
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

Re: [ZSCRIPT] Mikk's Dumb Questions

Post by Mikk- »

Okay so I'm just gonna turn this thread into a (possibly) dumb questions thread about various ZScript features and other such stuff.

In light of this; is it possible to create a GLSL shader that looks similar to the Black Phantoms of Dark Souls?
Spoiler:
I don't know much about shaders, I do however know that they can do some cool shit like that FillSpectre shader - which is actually what gave me the idea.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: [ZSCRIPT] Mikk's Dumb Questions

Post by Blue Shadow »

Mikk- wrote:Okay so I'm just gonna turn this thread into a (possibly) dumb questions thread about various ZScript features and other such stuff.
It's better to create a separate thread for each problem, instead of piling them up in a single thread. There's a reason, after all, for the editing forum organization that took place recently.
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

Re: [ZSCRIPT] Mikk's Dumb Questions

Post by Mikk- »

Oh, okay! I didn't want to clog up the editing forums, that's all.
Post Reply

Return to “Scripting”