Using a user variable in a weapon definition causes problems

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
SPZ1
Posts: 388
Joined: Wed Aug 02, 2017 3:01 pm
Location: Illinois
Contact:

Using a user variable in a weapon definition causes problems

Post by SPZ1 »

I discovered that using a user variable in a weapon's definition causes the game to freak out. What I didn't know is why. It happens in DECORATE as well as ZSCRIPT.

Code: Select all

ACTOR Triple_Element_Spell : Weapon {
	SpawnID 205
	// 251 x 229
	Scale 0.25
	Radius 32
	Height 57
	+FLOATBOB
	Weapon.AmmoType1 "Triple_Element_Spell_Ammo"
	Weapon.AmmoGive1 4
	Weapon.AmmoUse1 1
	Weapon.SelectionOrder 250
	Weapon.SlotNumber 7
	Weapon.SlotPriority 0.1
	AttackSound "weapons/Triple_Element_Spell/Shoot"
	Inventory.PickupMessage "You have obtained the Triple Element Spell!"

	var int user_ToggleZoom;

	States {
		Spawn:
			TRIG A 1 BRIGHT
			TRIG A 1 BRIGHT {
				user_ToggleZoom = 0;
			}

			Loop
		Ready:
			TRIG B 1 A_WeaponReady(WRF_ALLOWZOOM)
			Loop
		Select:
			TRIG B 1 A_Raise
			Loop
		DeSelect:
			TRIG B 1 A_Lower
			Loop
		Fire:
			TRIG B 16
			TRIG B 16 {
				A_RailAttack(random(65, 80), 50, TRUE, "Red", "none", RGF_FULLBRIGHT, 0, "none", 0.0, 0.0, 7168.0, 55, 1.3, 1.0, "none", 3.0);
				A_RailAttack(random(65, 80), 5, FALSE, "Green", "none", RGF_FULLBRIGHT, 0, "none", 0.0, 0.0, 7168.0, 55, 1.3, 1.0, "none", 3.0);
				A_RailAttack(random(65, 80), 25, FALSE, "Blue", "none", RGF_FULLBRIGHT, 0, "none", 0.0, 0.0, 7168.0, 55, 1.3, 1.0, "none", 40.0);
			}

			GoTo Ready

		Zoom:
			TRIG B 1 {
				if (user_ToggleZoom == 1){
					user_ToggleZoom = 0;
					A_ZoomFactor(1.0);
				} else {
					user_ToggleZoom = 1;
					A_ZoomFactor(3.0);
				}
			}

			GoTo Ready

	}
}
Image 1
Image 1
Image 2
Image 2
User avatar
SanyaWaffles
Posts: 866
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: Using a user variable in a weapon definition causes prob

Post by SanyaWaffles »

in ZScript try using invoker.user_ToggleZoom instead.

I don't think variables like that work in DECORATE.
User avatar
SPZ1
Posts: 388
Joined: Wed Aug 02, 2017 3:01 pm
Location: Illinois
Contact:

Re: Using a user variable in a weapon definition causes prob

Post by SPZ1 »

Of course they do just not when inheriting from a weapon
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Using a user variable in a weapon definition causes prob

Post by Apeirogon »

It says MAY not WILL. Gzdoom just not sure where user_ToggleZoom variable it should use, since simple variable name implicitly mean "class that execute this code". And for weapon case its player, player execute all weapons code.
So for zscript use invoker.name and for decorate, store variables in player
https://zdoom.org/wiki/User_variable#Conditions
User avatar
SPZ1
Posts: 388
Joined: Wed Aug 02, 2017 3:01 pm
Location: Illinois
Contact:

Re: Using a user variable in a weapon definition causes prob

Post by SPZ1 »

I was hoping there was some way to do it inside the ACTOR definition. Oh well... I have it working using an ACS library now. :thumb:
User avatar
SanyaWaffles
Posts: 866
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: Using a user variable in a weapon definition causes prob

Post by SanyaWaffles »

SPZ1 wrote:Of course they do just not when inheriting from a weapon
That's what I meant. :\
Post Reply

Return to “Scripting”