Journalist_Kuro Posted February 13, 2023 Hello Doom world! Some time ago i started to learning ZScript. After a while working on project i run into a problem with code itself. I've tried to create my own function with adjusted integer variable. Where it's increases global variable for specific amount (HyperAmount) If that variable is greater than 100 it's deploying specific message. When i run GZDoom i have errors for 8th and 11th lines: Quote 8th line: Unexpected ')' Expecting ';' 11th line: Unexpected '>' Expecting '-' or '+' or '++' or '--' or '(' or identifier or string constant or integer constant or 'super' or '~' or '!' or 'sizeof' or 'alignof' or unsigned constant or float constant or name constant or 'false' or 'true' or 'null' Here is my function that i've made: class NewWeapon : Weapon{ States{ void A_Hyper(int HyperAmount){ //First error let g = HyperVariables.Get(); if (g.HyperStack > 100){ //Second error Console.Printf("Hit Hyper max value!"); } else{ g.HyperStack += HyperAmount; Console.Printf("My given Hyper equal: %d" + HyperAmount); } } } } Hope someone will help me :) 0 Quote Share this post Link to post
jaeden Posted February 13, 2023 Functions (non-anonymous) should be defined outside the States block. 1 Quote Share this post Link to post
Journalist_Kuro Posted February 14, 2023 6 hours ago, jaeden said: Functions (non-anonymous) should be defined outside the States block. Thanks you so much! Your solution helped me :) ZScript feels kinda funky after Unity, haha 0 Quote Share this post Link to post
Journalist_Kuro Posted February 17, 2023 Well, while creating mode i AGAIN run into an issue This time i cant use global variable inside statusbar class It's gives me "Can't call play function Get from ui context". I guess Statusbar don't want to work with global variables..? Here is code from HUD: Spoiler class myStatusBar : BaseStatusBar { int shownHp; override void Init(){ super.Init(); SetSize(0,320,200); shownHp = 0; } override void Tick(){ int health = CPlayer.mo.health; Super.Tick(); } override void Draw(int state, double TicFrac){ Super.Draw (state, TicFrac); fullscreenOffsets = true; int health = CPlayer.mo.health; int my_armor = GetArmorAmount(); let g = HyperVariables.Get(); HUDFont bigFont = HUDFont.Create("BIGFONT2"); DrawString(bigFont, FormatNumber(health),(40,-25)); DrawString(bigFont, FormatNumber(my_armor),(40,-45)); DrawString(bigFont, FormatNumber(g.HyperStack),(40,-65)); DrawImage("HUD_SMOL", (24, -30)); DrawImage("HUD_ARBG", (24, -32)); DrawImage("HUD_AR", (24, -32)); DrawImage("HUD_SMOL", (24, -10)); DrawImage("HUD_HPBG", (24, -12)); DrawImage("HUD_HP", (24, -12)); DrawImage("HUD_SMOL", (-24, -10)); DrawImage("HUD_HYBG", (-24, -12)); DrawImage("HUD_HY", (-24, -12)); DrawString(bigFont, FormatNumber(health),(40,-20));*/ } } And code for global variables itself (If needed): Class HyperVariables : Thinker { int HyperStack; bool HyperSwitch; HyperVariables Init(){ ChangeStatNum(STAT_STATIC); return self; } static HyperVariables Get() { let it = ThinkerIterator.Create('HyperVariables', STAT_STATIC); HyperVariables cur, prev = null; while((cur = HyperVariables(it.Next())) != null){ if (prev != null){ prev.Destroy(); } prev = cur; } if(prev == null){ prev = new('HyperVariables').Init(); } return prev; } } 0 Quote Share this post Link to post
Edward850 Posted February 17, 2023 (edited) If my assumption is correct, it's the thinker iteration and destruction. You cannot do things that modify the playsim from the UI. Edited February 17, 2023 by Edward850 0 Quote Share this post Link to post
Journalist_Kuro Posted February 18, 2023 11 hours ago, Edward850 said: If my assumption is correct, it's the thinker iteration and destruction. You cannot do things that modify the playsim from the UI. So its not possible to use global variables in Statusbars? 0 Quote Share this post Link to post
Edward850 Posted February 18, 2023 Not like that, no. Any variables you handle from the playsim to the UI have to be considered read only. I don't know enough about zscript to say how that's done. 0 Quote Share this post Link to post
boris Posted February 18, 2023 Yes, it has to do with scopes, see https://zdoom.org/wiki/Object_scopes_and_versions#Scoping_system You have to use network events to have interaction between the ui and playsim: https://zdoom.org/wiki/Events_and_handlers#Networking 0 Quote Share this post Link to post
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.