[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.

[ZSCRIPT] Mikk's Dumb Questions

Postby Mikk- » Fri Dec 08, 2017 4:25 pm

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' GetUserVariable & SetUserVariable. 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 6:09 pm, edited 1 time in total.
User avatar
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: [ZSCRIPT] Variables reset upon respawn

Postby AFADoomer » Sat Dec 09, 2017 12:21 pm

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
AFADoomer
 
Joined: 15 Jul 2003

Re: [ZSCRIPT] Variables reset upon respawn

Postby Mikk- » Sat Dec 09, 2017 12:25 pm

The player is actually respawning, the maps have allowrespawn enabled in MAPINFO
User avatar
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: [ZSCRIPT] Variables reset upon respawn

Postby Graf Zahl » Sat Dec 09, 2017 3:40 pm

The player which respawns is a completely new actor which will not get the values of the previous version transferred to it.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: [ZSCRIPT] Variables reset upon respawn

Postby Mikk- » Thu Dec 14, 2017 8:10 am

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
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: [ZSCRIPT] Variables reset upon respawn

Postby Nash » Thu Dec 14, 2017 9:22 am

Would storing the variables on an undepletable inventory inside the player work?
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [ZSCRIPT] Variables reset upon respawn

Postby Mikk- » Thu Dec 14, 2017 9:29 am

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
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: [ZSCRIPT] Variables reset upon respawn

Postby Nash » Thu Dec 14, 2017 9:37 am

Try this.
Attachments
player variable.pk3
(3.53 KiB) Downloaded 32 times
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [ZSCRIPT] Variables reset upon respawn

Postby Mikk- » Thu Dec 14, 2017 1:35 pm

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 allExpand view
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 allExpand view
    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
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: [ZSCRIPT] Variables reset upon respawn

Postby Nash » Fri Dec 15, 2017 2:20 am

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 34 times
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [ZSCRIPT] Variables reset upon respawn

Postby Mikk- » Fri Dec 15, 2017 8:45 am

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 allExpand view
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 variableint 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
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: [ZSCRIPT] Variables reset upon respawn

Postby Nash » Fri Dec 15, 2017 11:54 am

Good job! Hope you have fun learning ZScript. It's not as scary as some people make it out to be. :D
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: [ZSCRIPT] Mikk's Dumb Questions

Postby Mikk- » Fri Dec 15, 2017 6:20 pm

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.
User avatar
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: [ZSCRIPT] Mikk's Dumb Questions

Postby Blue Shadow » Fri Dec 15, 2017 9:11 pm

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
Blue Shadow
 
 
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: [ZSCRIPT] Mikk's Dumb Questions

Postby Mikk- » Sat Dec 16, 2017 8:49 am

Oh, okay! I didn't want to clog up the editing forums, that's all.
User avatar
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest