Problems with using CallACS during item spawn?

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
TheRailgunner
Posts: 1556
Joined: Mon Jul 08, 2013 10:08 pm

Problems with using CallACS during item spawn?

Post by TheRailgunner »

I feel like this should work (the ACS function it calls does, for example - in this case, it's meant to tell the actor what weapon the player has equipped when it spawns XP items):

Code: Select all

actor TR_1XPa : CustomInventory
{
  inventory.pickupmessage "Your weapon gained 1 XP."
  //inventory.icon "ARTIINVU"
  inventory.maxamount 0
  +COUNTITEM
  +FLOATBOB
  //+AUTOACTIVATE
  Scale 0.25
  Inventory.Pickupsound "Weapons/SurfeitTorment/Upgrade"
  states
  {
  Spawn:
	TNT1 A 0 
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==17, "CSSpawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==16, "MDSpawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==15, "SASpawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==14, "M8Spawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==13, "LXSpawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==12, "D6Spawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==11, "LSSpawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==10, "FRSpawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==9, "V9Spawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==8, "M7Spawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==7, "V7Spawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==6, "N7Spawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==5, "PRSpawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==4, "PDSpawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==3, "MBSpawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==2, "ASSpawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==1, "X7Spawn")
	TNT1 A 0 A_JumpIf(CallACS("WeaponSelected")==0, "STSpawn")
	TNT1 A -1
	Loop
  STSpawn:
	TNT1 A 0 A_SpawnItem("STXP_1")
    Stop
  X7Spawn:
	TNT1 A 0 A_SpawnItem("X7XP_1")
    Stop
  ASSpawn:
	TNT1 A 0 A_SpawnItem("ASXP_1")
    Stop
  MBSpawn:
	TNT1 A 0 A_SpawnItem("MBXP_1")
    Stop
  PDSpawn:
	TNT1 A 0 A_SpawnItem("PDXP_1")
    Stop
  PRSpawn:
	TNT1 A 0 A_SpawnItem("PRXP_1")
    Stop
  N7Spawn:
	TNT1 A 0 A_SpawnItem("N7XP_1")
    Stop
  V7Spawn:
	TNT1 A 0 A_SpawnItem("V7XP_1")
    Stop
  M7Spawn:
	TNT1 A 0 A_SpawnItem("M7XP_1")
    Stop
  V9Spawn:
	TNT1 A 0 A_SpawnItem("V9XP_1")
    Stop
  FRSpawn:
	TNT1 A 0 A_SpawnItem("FRXP_1")
    Stop
  LSSpawn:
	TNT1 A 0 A_SpawnItem("LSXP_1")
    Stop
  D6Spawn:
	TNT1 A 0 A_SpawnItem("D6XP_1")
    Stop
  LXSpawn:
	TNT1 A 0 A_SpawnItem("LXXP_1")
    Stop
  M8Spawn:
	TNT1 A 0 A_SpawnItem("M8XP_1")
    Stop
  SASpawn:
	TNT1 A 0 A_SpawnItem("SAXP_1")
    Stop
  MDSpawn:
	TNT1 A 0 A_SpawnItem("MDXP_1")
    Stop
  CSSpawn:
	TNT1 A 0 A_SpawnItem("CSXP_1")
    Stop
  }
}
Is there something I'm missing?
Gez
 
 
Posts: 17835
Joined: Fri Jul 06, 2007 3:22 pm

Re: Problems with using CallACS during item spawn?

Post by Gez »

How is it not working?

Also I feel like that the code could probably be massively simplified by moving to ZScript.
User avatar
TheRailgunner
Posts: 1556
Joined: Mon Jul 08, 2013 10:08 pm

Re: Problems with using CallACS during item spawn?

Post by TheRailgunner »

Gez wrote:How is it not working?

Also I feel like that the code could probably be massively simplified by moving to ZScript.
Basically, it acts like it never makes the call to the ACS script (the only difference between this spawning item and others like it in my mod is that this one determines what to spawn upon drop, whereas the others determine what to spawn at the start of the map), even though the script itself is functional.

And yes, ZScript would be simpler, but it would require a rewrite of the mod entirely (that, and I'd have to essentially learn a minor programming language to use it at all - oh, and semicolons).

Here is the script itself:

Code: Select all

Script "WeaponSelected" ENTER
{
int st = 0;
int x7 = 0;
int as = 0;
int mb = 0;
int pd = 0;
int pr = 0;
int n7 = 0;
int v7 = 0;
int m7 = 0;
int v9 = 0;
int fr = 0;
int ls = 0;
int d6 = 0;
int lx = 0;
int m8 = 0;
int sa = 0;
int md = 0;
int cs = 0;
	While(1) {
		st = CheckActorInventory((1000 + PlayerNumber()),"STSelected");
		x7 = CheckActorInventory((1000 + PlayerNumber()),"X7Selected");
		as = CheckActorInventory((1000 + PlayerNumber()),"ASSelected");
		mb = CheckActorInventory((1000 + PlayerNumber()),"MBSelected");
		pd = CheckActorInventory((1000 + PlayerNumber()),"PDSelected");
		pr = CheckActorInventory((1000 + PlayerNumber()),"PRSelected");
		n7 = CheckActorInventory((1000 + PlayerNumber()),"N7Selected");
		v7 = CheckActorInventory((1000 + PlayerNumber()),"V7Selected");
		m7 = CheckActorInventory((1000 + PlayerNumber()),"M7Selected");
		v9 = CheckActorInventory((1000 + PlayerNumber()),"V9Selected");
		fr = CheckActorInventory((1000 + PlayerNumber()),"FRSelected");
		ls = CheckActorInventory((1000 + PlayerNumber()),"LSSelected");
		d6 = CheckActorInventory((1000 + PlayerNumber()),"D6Selected");
		lx = CheckActorInventory((1000 + PlayerNumber()),"LXSelected");
		m8 = CheckActorInventory((1000 + PlayerNumber()),"M8Selected");
		sa = CheckActorInventory((1000 + PlayerNumber()),"SASelected");
		md = CheckActorInventory((1000 + PlayerNumber()),"MDSelected");
		cs = CheckActorInventory((1000 + PlayerNumber()),"CSSelected");
			if(st != 0) {
				SetResultValue(0);
				//print(s:"Surfeit Torment Equipped");
				Delay(1);
			}
			else if(x7 != 0) {
				SetResultValue(1);
				//print(s:"XM27 Equipped");
				Delay(1);
			}
			else if(as != 0) {
				SetResultValue(2);
				//print(s:"Automat Sokova Equipped");
				Delay(1);
			}
			else if(mb != 0) {
				SetResultValue(3);
				//print(s:"MARS B Equipped");
				Delay(1);
			}
			else if(pd != 0) {
				SetResultValue(4);
				//print(s:"Pulsar-D Equipped");
				Delay(1);
			}
			else if(pr != 0) {
				SetResultValue(5);
				//print(s:"M41A Equipped");
				Delay(1);
			}
			else if(n7 != 0) {
				SetResultValue(6);
				//print(s:"Nishimura Seven Equipped");
				Delay(1);
			}
			else if(v7 != 0) {
				SetResultValue(7);
				//print(s:"VSK7 Equipped");
				Delay(1);
			}
			else if(m7 != 0) {
				SetResultValue(8);
				//print(s:"M97 Equipped");
				Delay(1);
			}
			else if(v9 != 0) {
				SetResultValue(9);
				//print(s:"VSK9 Equipped");
				Delay(1);
			}
			else if(fr != 0) {
				SetResultValue(10);
				//print(s:"DGA-3 Equipped");
				Delay(1);
			}
			else if(ls != 0) {
				SetResultValue(11);
				//print(s:"Last Salvo Equipped");
				Delay(1);
			}
			else if(d6 != 0) {
				SetResultValue(12);
				//print(s:"DM-6 Equipped");
				Delay(1);
			}
			else if(lx != 0) {
				SetResultValue(13);
				//print(s:"Luxor HMG Equipped");
				Delay(1);
			}
			else if(m8 != 0) {
				SetResultValue(14);
				//print(s:"Mark 48 Equipped");
				Delay(1);
			}
			else if(sa != 0) {
				SetResultValue(15);
				//print(s:"Sharpshooter Arm Equipped");
				Delay(1);
			}
			else if(md != 0) {
				SetResultValue(16);
				//print(s:"Machiavellian Disciple Equipped");
				Delay(1);
			}
			else if(cs != 0) {
				SetResultValue(17);
				//print(s:"Crimson Spectre Equipped");
				Delay(1);
			}
			else {
				SetResultValue(18);
				//print(s:"No Weapon Equipped");
				Delay(1);
			}
		Delay(1);
		}
}
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Problems with using CallACS during item spawn?

Post by Apeirogon »

So, ACS must execute in first ticks of actor "life"? Or wait until player step on/in it?
Have you tried to use nodelay?

Also

Code: Select all

   TNT1 A -1
   Loop
-->

Code: Select all

   tnt1 a 1
   loop
Because -1 means "actor remain in state forever", but I not sure...


TheRailgunner wrote:require a rewrite of the mod entirely
Nope. You can inherit decorate actor from zscript class, spawn decorate actors and zscript class in same time, use zscript functions of class in decorate actors if it inherit from this class, use zscript events with decorate and acs functions, etc.
Look at high noon drifter. it is written in half on decorate and in half on zscript.
User avatar
TheRailgunner
Posts: 1556
Joined: Mon Jul 08, 2013 10:08 pm

Re: Problems with using CallACS during item spawn?

Post by TheRailgunner »

Apeirogon wrote:So, ACS must execute in first ticks of actor "life"? Or wait until player step on/in it?
Have you tried to use nodelay?

Also

Code: Select all

   TNT1 A -1
   Loop
-->

Code: Select all

   tnt1 a 1
   loop
Because -1 means "actor remain in state forever", but I not sure...


TheRailgunner wrote:require a rewrite of the mod entirely
Nope. You can inherit decorate actor from zscript class, spawn decorate actors and zscript class in same time, use zscript functions of class in decorate actors if it inherit from this class, use zscript events with decorate and acs functions, etc.
Look at high noon drifter. it is written in half on decorate and in half on zscript.
NoDelay seems to have no effect - it literally seems like it just doesn't execute the CallACS in this manner. Right now the XP system is on pickup (which works without ACS), but I want to change it to on-drop (making XP drop specifically for weapons that killed the actors that drop XP).
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Problems with using CallACS during item spawn?

Post by Arctangent »

The issue, from what I can tell, is that you have no idea what CallACS actually does.

From what I can tell just from your code alone, you seem to think that you can execute a script beforehand ( or, rather, have it be executed for you through ENTER and the like ), then CallACS will be able grab that exact instance of the script ( somehow magically knowing which instance of the script you want ) and you'll be able to grab a result value from it. There are several problems with this:
  1. This is not how CallACS ( or [wiki]ACS_ExecuteWithResult[/wiki], as CallACS is just an alias for that ) works in the slightest. Each CallACS call is creating another instance of the script and running it, so having said script be an ENTER one is completely pointless. This also means that not only does the fact that that script you're executing is an infinite loop means that you're slowly clogging up the player's memory by forcing ZDoom to run more and more scripts that never end, but ...
  2. This is not how [wiki]SetResultValue[/wiki] works. CallACS is special in that it calls the script synchronously as opposed to how all other script executions are called asynchronously. This means that the moment ZDoom processes CallACS, it wastes no time to going through entirety of the script to find a result value ... which breaks immediately upon finding a Delay call, resulting in the script becoming asynchronous again and further result values being tossed into the void.
  3. This is not how [wiki]PlayerNumber[/wiki] works. You're calling the script from an inventory item, which means the script's activator is the item. PlayerNumber gets, well, the number of the player activating the script. Items, however, aren't players, so PlayerNumber will return -1, and somehow I doubt a thing with the tid of 999 is relevant at all to anything you're doing. This also means that [wiki]CheckWeapon[/wiki] would be infinitely better than this method of using dummy items to represent what weapon the player has out, since you'd need to set the script's activator to the player through something like [wiki]SetActivatorToTarget[/wiki] anyway.
Honestly, learning ZScript might take less time than figuring out how to hack all of this together to consider what happens when a monster dies to infighting, or to the world, or so on and so on. This absolutely seems like a system that'll only cause headaches if you try to do it in ACS + Decorate.
Post Reply

Return to “Scripting”