Global Scripting - integers not sticking

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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!)
User avatar
AnotherLurker
Banned User
Posts: 36
Joined: Wed May 24, 2017 10:58 am

Global Scripting - integers not sticking

Post by AnotherLurker »

I've recently learned how to make a global script (for the sticklers, yes I know it's called something else, but us dull boring mortals call it 'global' script)
and I've come across a rather alarming problem. I have a lot of my scripts based off of integers (or whatever they're called), but scripts that depend on these don't
stick when passing on from one level to the next.. They reset.

This short piece of code is just to demonstrate it.

Code: Select all

int value = 0;

Script 1 (void)
{
value = value +1;
}

Script 2 (void)
{
print (s:"Value is at..." d:value)
}
Say I'm on map one.. I activate script 2. It'll say the value is at 0. I activate script 1, then 2 again. It'll say the value is at 1.
If I pass over to map two, then activate script 2, it'll say the value is at 0 again.

How do I make the value stay according to how it's been changed, through map changes?
User avatar
TDRR
Posts: 836
Joined: Sun Mar 11, 2018 4:15 pm
Location: Venezuela

Re: Global Scripting - integers not sticking

Post by TDRR »

Give Inventory Items to the player and use them as counters for whatever purpose you need them, it's hacky but i doubt there's another way to keep values between levels.

You could also use ZScript but it wouldn't be good if you want Zandronum compatibility.

If you don't know how to do this here's some example code:
DECORATE

Code: Select all

Actor CounterForACSScript : Inventory {Inventory.MaxAmount 50}
ACS

Code: Select all


Script 1 (void) //Assuming the player activates this.
{
GiveInventory("CounterForACSScript", 1);
}

Script 2 (void)
{
int value = CheckInventory("CounterForACSScript");
print (s:"Value is at..." d:value);
}
User avatar
AnotherLurker
Banned User
Posts: 36
Joined: Wed May 24, 2017 10:58 am

Re: Global Scripting - integers not sticking

Post by AnotherLurker »

it's hacky but i doubt there's another way
I'm sensing a pattern here...

Thank you, but sadly a solution as hacky as that might be a bit too far out of my grasp at this point.. I (once again) foolishly overestimated the user-friendliness of the engine, so having to downgrade everything to the inventory system bit by painstaking bit would run a strong risk to embitter the entire ideal of the project to begin with..

Honestly, I was naively expecting a solution to this like some simple command I missed or a work-around involving a different variable, but the fact that a global script apparently doesn't hold integers/variables/ect
between maps slightly vexes me, when inventory items, a far more basic thing, does.

I'd complain about it, but I can already hear the betrayed gasps and the "how dare you"s, so yeah, no point in bothering..

Sure gets tiring being told to jump through hoops just to compensate for issues that probably shouldn't exist in the first place..
Oh, but how could I forget their priceless tech support slogan.. "if you aren't smart enough to fix it yourself, shut the **** up."

I'd scrap my project and release it to at least show off what I'd done, but nobody'd look at it. Oh well, there's something liberating about starting fresh.. Like taking a high-level character and just
importing them into a new game, with all their stats and skills in-tact.. This isn't an appalling failure, it's just a lesson in aiming a little too high.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm

Re: Global Scripting - integers not sticking

Post by Arctangent »

AnotherLurker wrote:Sure gets tiring being told to jump through hoops just to compensate for issues that probably shouldn't exist in the first place..
they don't exist in the first place

please tone down the jackassery, it's plainly blinding you at this point
User avatar
AnotherLurker
Banned User
Posts: 36
Joined: Wed May 24, 2017 10:58 am

Re: Global Scripting - integers not sticking

Post by AnotherLurker »

After the things I'd been frankly told when conversing with devs, I wasn't exactly brimming with confidence over the likelihood of future problems being solvable by non-hacky means, so pardon me if I was ready to dig a grave for my project before waiting for a normal solution to be found. (I was only very slightly exaggerating about that slogan..)

Anyway, this does seem to be exactly what I was looking for.. Like many things pertaining to this, it's something who's name I'd have probably never have come
across searching on my own, and was something I'd have to hope someone else knew about and tell me when referring to wanting something similar to it.

The knowledge around these advanced things can be very mystifying at times, and that's what preemptively frustrates me.. Unless you're already a guru, or a highly experienced forum-surfer (I am neither, and will predictably be criticized for it), the only way you can progress in skill is borrowed knowledge, leaving you at the mercy of the community.. Who could help you.. But might just as equally be likely to bash you or laugh at you for it.. An environment like that might make someone want to make sure they're loaded for bear before entering it..

But I get what you're saying.. Probably not the best idea to over-equip for a fight that might not even take place.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm

Re: Global Scripting - integers not sticking

Post by Arctangent »

AnotherLurker wrote:the only way you can progress in skill is borrowed knowledge.
it is legitimately the first result for page text matching when you search "global variables", and "global variable" for that matter

even then, that page is literally listed under "basics" on the main [wiki]ACS[/wiki] page, so doing some light reading when you got stumped would've lead you that page pretty quickly even if you had no idea that the "global" moniker you were already using could be applied to variables
User avatar
AnotherLurker
Banned User
Posts: 36
Joined: Wed May 24, 2017 10:58 am

Re: Global Scripting - integers not sticking

Post by AnotherLurker »

I figured because of the way the wiki puts it, that variables are different from integers.. In fact, you may be very surprised at just how ignorant I really am, as I do not know the actual difference BETWEEN a variable and integer..

I'm literally just feeling myself through this in the dark, learning bits and scraps as I go along, because the only way to make ever better mods is to force myself into this scary world of sub-computer-programming-code stuff in order to make certain things work.. (Just about 2 or more months ago, I didn't even know how to USE integers in ACS scripting.. I was just using ACS for basic functions)

If I was smart enough to have already gained a grasp on all that, sure, I probably wouldn't have ever needed to come here.. Ever.. But intellectually speaking, I'm basically crawling in the dirt here, I haven't even gotten up to a walking pace on handling some of these things. Yes, it's probably seems ungrateful of me to barge in knowing so little but asking so much, but so much of this information critically hinges on you already knowing prerequisite knowledge that unless you pretty much already know basic programming code, you HAVE to come in blind as a bat at first..

I'm having the same problem with this.. Even setting it as a global variable, it's still resetting when changing map.. What am I doing wrong?

Code: Select all

global int 1:value;

Script 1 ENTER
{
value = 15;
}

Script 2 (void)
{
print (s:"Value is..." d:value)
}

{Script 3 (void)
{
value = value +1
}
Doing it this way seems to disable you from setting an integor value to it without doing so in an ENTER script, unless I'm missing some other variable to the process.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm

Re: Global Scripting - integers not sticking

Post by Arctangent »

AnotherLurker wrote:I figured because of the way the wiki puts it, that variables are different from integers.. In fact, you may be very surprised at just how ignorant I really am, as I do not know the actual difference BETWEEN a variable and integer..
integers are a type of variable which is used to store whole numbers

if by "the way the wiki puts it" you mean the "In reality ACS only supports one data type and that is the integer type." on this page, that is because acs's initial design did not plan beyond the scope of level scripting in a single 1995 game. all it means that acs is basically dynamically typed even though it appears to be statically typed, because in reality everything's an integer that's being interpreted as not an integer ( i.e. having half of its bits being interpreted as decimal values for functions expecting fixed point numbers, or using the user-hidden integer as a position in the internal string table for functions expecting a string )

that all said, you should still "type" your variables correctly, as you shouldn't make a habit of assigning strings to variables expecting integers, as any actually statically typed language ( such as zscript ) will not even let you attempt that
User avatar
AnotherLurker
Banned User
Posts: 36
Joined: Wed May 24, 2017 10:58 am

Re: Global Scripting - integers not sticking

Post by AnotherLurker »

I'm not cynical enough to consider that what you said doesn't pertain to my problem.
But I'm not intelligent enough to figure out if it does, either.

I know I'm out of my league with this stuff, I can't refute that.. But if I got this far, surely fixing this problem isn't going to be the concrete block that breaks the camel's back..
So I'll just try to ask plainly.

Is it possible to have a "global" integer value (in other words, a value attached to a number), that can change or stay the same after being changed, through different maps?
And if so, how exactly do I do/make/code that?.. Because in the page you suggested, it only shows a normal integer, but uses the wierd "1:value;" thing with a global one..
User avatar
Nash
 
 
Posts: 17513
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Global Scripting - integers not sticking

Post by Nash »

Here, have an example
You do not have the required permissions to view the files attached to this post.
User avatar
AnotherLurker
Banned User
Posts: 36
Joined: Wed May 24, 2017 10:58 am

Re: Global Scripting - integers not sticking

Post by AnotherLurker »

I tried to understand the example the best I could, and came up with this..

Code: Select all

global int 0:init;  
global int 1:value;  

Script 1 ENTER
{
if(init == 2) terminate;
init = 2; 
value = 15;
}

Script 2 (Void)
{
Print (s:"value is...", d:value)
}

Script 3 (void)
{
value = value +1;
}
Figuring that the ENTER script does indeed run every time a player enters a new map, I added on a section which assures the initial placement of the value is only ran ONCE, so it isn't just
reset every map, and made sure both values were "global" so that they could be tracked across different maps.

This still does not work.. On a map change, ALL values still reset.. Why?

Does making a variable global still not allow number-based values to stay the same across maps? Or is there some other piece of code I'm missing?
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: Global Scripting - integers not sticking

Post by Blue Shadow »

Does the code compile successfully? I see you're missing a semicolon at the end of the Print() call in script 2.
RedFoxGamer
Posts: 12
Joined: Mon Nov 19, 2018 1:10 am

Re: Global Scripting - integers not sticking

Post by RedFoxGamer »

It may not matter but for your ENTER script, try this:

Code: Select all

Script 1 ENTER
{
if(init==2)
{
Delay(1);
ACS_Terminate(1);
}
Else
{
Delay(1);
init=2;
value=15;
}
}
Oh and also, with global variables, you still have to int them on every map so the ACS script and thus the game still knows it’s a valid variable.

I am in the process of programming a basic RPG system for my game, and I extensively use global variables. Maybe take a look at my code for examples on how I use it. https://pastebin.com/AquBhjXy
User avatar
AnotherLurker
Banned User
Posts: 36
Joined: Wed May 24, 2017 10:58 am

Re: Global Scripting - integers not sticking

Post by AnotherLurker »

Now things are getting interesting..

A few of the problems were removed when I realized I still had a derelict copy of the script stuck over the first test map.
But it still doesn't update through a map change.
Oh and also, with global variables, you still have to int them on every map so the ACS script and thus the game still knows it’s a valid variable.
What if the mod I'm trying to make doesn't have any maps in it, and is simply a mod that can be made to attach to other wads?
Do I still do that? And if so, HOW do I do that?
User avatar
AnotherLurker
Banned User
Posts: 36
Joined: Wed May 24, 2017 10:58 am

Re: Global Scripting - integers not sticking

Post by AnotherLurker »

WOOOAAHHH....

Apparently removing the "test map" completely fixed everything!

So a global variable can stick to any map WITHOUT you needing to stick to each map, if it's within a global script, and there are no hand-made maps within the wad.

Well then, I guess that's that. My Christmas wish was granted.. Now to convert all the other variables into global ones, and continue on my way.

I figured the solution was something devilishly simple, but just outside of the reach of my capacity for curiosity.. I guess I just gotta keep the faith..

Merry christmas to all, and to all a good wad.


"Smile for the camera, honey!... .. O-okay, honey, tone it back a bit, you're creepin' me out."

Return to “Scripting”