zscript doesn't let me give integers values

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
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

zscript doesn't let me give integers values

Post by lemonTasteIceTea+ »

i used inventories as makeshift variables, but now i need to work with pure variables since i need them to be negative
in the head part of the class i can only do

Code: Select all

int a;
if i do

Code: Select all

int a = 0;
then it gives me

Code: Select all

Script error, "TGC.pk3:classes/sweps/slot2.zs" line 11:
Unexpected '='
Expecting ';' or ','
and if i do

Code: Select all

{ a = 0; }
in any state it gives me

Code: Select all

Unexpected '='
Expecting '-' or '+' or '++' or '--' or '(' or identifier or string constant
etc
how do i stop this from happening?
i have looked in mods and i don't see any big ol thing i might be missing
entire code snippet: https://pastebin.com/u83yiPwL
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: zscript doesn't let me give integers values

Post by ramon.dexter »

Initialize these values in override of PostBeginPlay.

Code: Select all

override void PostBeginPlay() {
Super.PostBeginPlay();
<your code>
a = 0;
}
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: zscript doesn't let me give integers values

Post by lemonTasteIceTea+ »

in the pastebin i do have a postbeginplay with that in but outside of it i can't change the variable
let me try again
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: zscript doesn't let me give integers values

Post by lemonTasteIceTea+ »

yeah the variable goes through the postbeginplay but as soon as i try to change it zdoom freaks out
can i only change variables in functions? the { a = 0; } i put in there is in a weapon state
7Soul
Posts: 41
Joined: Sat Mar 13, 2021 6:47 pm

Re: zscript doesn't let me give integers values

Post by 7Soul »

You can make them into a property if you want to modify outside of functions.

Code: Select all

int a;
Property a:a;

Default {
    TGCpistol.a 5;
}
PS: you don't need to set an int to 0 since ints are by default already set to 0
Last edited by 7Soul on Tue Oct 04, 2022 5:43 pm, edited 1 time in total.
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: zscript doesn't let me give integers values

Post by lemonTasteIceTea+ »

i have been trying all day to get the property thing to work but it gives me the same thing as { a = 1; }(for the ps i do know that int default to 0 but i gave that as an example)

Code: Select all

class test : inventory {
	int a;
	property a:a;
	default {
	test.a = 2;
	}	
}

Code: Select all

Script error, "TGC.pk3:classes/test.zs" line 5:
Unexpected '='
Expecting '-' or '+' or '++' 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'
7Soul
Posts: 41
Joined: Sat Mar 13, 2021 6:47 pm

Re: zscript doesn't let me give integers values

Post by 7Soul »

My bad, in default {} we don't use =
(i'll edit my previous post)
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: zscript doesn't let me give integers values

Post by lemonTasteIceTea+ »

that does solve it in the default{} but not in states{}
in that test class i wrote

Code: Select all

Spawn:
PISG A -1
{
int a = 5;
}
stop;
and it works beautifully but in the tgcpistol class it just throws at me

Code: Select all

Script error, "TGC.pk3:classes/sweps/slot2.zs" line 54:
Unexpected ';'
Expecting identifier
sorry for the spam on this post but i think zscript hates me
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: zscript doesn't let me give integers values

Post by ramon.dexter »

Okay, where is the line 54? When posting a code, please mark the error line, so others dont have to ask you a question such as this one.
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: zscript doesn't let me give integers values

Post by lemonTasteIceTea+ »

Code: Select all

		ReadyAgainAgain:
		PISG A 1 a_WeaponReady();
		{
			int a = 8;
			//a_LogInt(a);
		}
		loop;
sorry, 54 is where loop; is
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: zscript doesn't let me give integers values

Post by lemonTasteIceTea+ »

https://pastebin.com/QDLhDsMd also new pastebin due to the 2 changes to the code
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: zscript doesn't let me give integers values

Post by ramon.dexter »

When you want to change value of a defined variable, you don't redefine it. So, on the start of code:

Code: Select all

int a;
And in states:

Code: Select all

a = <desired value>;
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: zscript doesn't let me give integers values

Post by lemonTasteIceTea+ »

good news is that it doesn't get angry at the loop anymore but now it's getting angry at the = sign again

Code: Select all

Script error, "TGC.pk3:classes/sweps/slot2.zs" line 51:
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'

Code: Select all

ReadyAgainAgain:
		PISG A 1 a_WeaponReady();
		{
			a = 8;
			//a_LogInt(a);
		}
the trouble line is a = 8;
love how this post still hasn't died yet
7Soul
Posts: 41
Joined: Sat Mar 13, 2021 6:47 pm

Re: zscript doesn't let me give integers values

Post by 7Soul »

Anonymous functions are done like this:

Code: Select all

ReadyAgainAgain:
		PISG A 1 {
			a_WeaponReady();
			a = 8;
			//a_LogInt(a);
		}
Everything has to go in the brackets

I recommend you check out this zscript guide: https://github.com/jekyllgrim/ZScript_Basics, part 6 explains anonymous functions in more detail
lemonTasteIceTea+
Posts: 16
Joined: Sun Oct 02, 2022 12:57 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch
Graphics Processor: nVidia with Vulkan support

Re: zscript doesn't let me give integers values

Post by lemonTasteIceTea+ »

that was it! thank you all!
i did need to add invoker. to the beginning though
Post Reply

Return to “Scripting”