I don't get ACS

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
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

I don't get ACS

Post by Sergeant Hoppy »

I have experimented all day with getting ACS files going but I can't seem to get it right.

I have an experiment going and I got an ACS file the root called GIVEWEAPON

The code inside is:

Code: Select all

#include zcommon.acs

script 1 ENTER
{
        Print(s:"Hello!");
}
When compiling I get this message:
Line 1 in file "C:\Users\mukhtaar\AppData\Roaming\SLADE3\temp\GIVEWEAPON.acs" ...
C:\Users\mukhtaar\AppData\Roaming\SLADE3\temp\GIVEWEAPON.acs:1: String literal not found.
> #include zcommon.
> ^

What is going on?
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: I don't get ACS

Post by Jarewill »

#include takes a string, which is defined with "quotation marks"
So you will have to add them:

Code: Select all

#include "zcommon.acs" 
After compiled, you will also need to create a LOADACS file and put in it the ACS filename.
In your case, LOADACS would include the text GIVEWEAPON without "quotation marks" and anything else.
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

Re: I don't get ACS

Post by Sergeant Hoppy »

I see, thank you for helping out! I got it working now.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: I don't get ACS

Post by Gez »

Jarewill wrote:After compiled, you will also need to create a LOADACS file and put in it the ACS filename.
In your case, LOADACS would include the text GIVEWEAPON without "quotation marks" and anything else.
For use with LOADACS, it also has to be declared as a [wiki]library[/wiki]. Which means you need to add #library "GIVEWEAPON" as the first line (before #include "zcommon.acs").
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

Re: I don't get ACS

Post by Sergeant Hoppy »

Thank you, I managed to get it working, and I'm able to give custom weapons to the player when starting the game.

I'm still having a bit of trouble with how to structure things, I'm fiddling with health regeneration, I can get it to work but I'm trying to add a condition where it only triggers if the health is below 50, and that is where it falls apart, it won't trigger, how come?

Code: Select all

#include "zcommon.acs"

script 2 ENTER
{ int health = GetActorProperty (0, APROP_HEALTH);
	{
	while(health < 50);
	healthing(1,50);
	delay(35*1);
	restart;
	}
}
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: I don't get ACS

Post by Jarewill »

As it is, the script will stop immediately.
That's because it doesn't loop if the player has above 50 health, making it terminate.
Adding another Delay() and Restart after the While check should make it work properly.

Also as Gez said, you should also include a #library.
Without a #library, the script will break with maps that use ACS.
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

Re: I don't get ACS

Post by Sergeant Hoppy »

Hmm, it is still not triggering, I must have missunderstood?

Code: Select all

#library "REGEN"
#include "zcommon.acs"

script 2 ENTER
{ int health = GetActorProperty (0, APROP_HEALTH);
   {
   while(health < 50);
   delay(35*1);
   restart;
   healthing(1,50);
   delay(35*1);
   restart;
   }
}
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: I don't get ACS

Post by Jarewill »

Now the While loop never triggers, because it ends with ; instantly and the script restarts before it gets to the healing part.
Try this:

Code: Select all

script 2 ENTER
{ int health = GetActorProperty (0, APROP_HEALTH);
   if(health < 50) //While isn't even needed here, If is enough
   {
   delay(35*1);
   healthing(1,50); //Heal the player
   restart; //Restart the script
   }
   delay(1); //Otherwise loop it
   restart;
} 
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

Re: I don't get ACS

Post by Sergeant Hoppy »

Yes, that works, though I don't understand the logic in how the extra delay(1) and restart tells the script to loop, if it wouldn't be to much trouble could I inquire on how it works on a more technical note?

And thanks once again for helping out.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: I don't get ACS

Post by Jarewill »

Restart tells the script to, well, restart making it loop.
However if you restart without a delay, the script will self-terminate to avoid freezing the game.
Delay(1); Restart; is often used for looping scripts because of that.

Alternatively you can do a While(true) loop:

Code: Select all

While(true)
{
    Delay(1);
    //Do stuff
} 
I don't know the difference between restarting and using While though.
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

Re: I don't get ACS

Post by Sergeant Hoppy »

Ahh, I get it! a delay is required with a restart to avoid it ending, then. Thank you for explaining it.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: I don't get ACS

Post by ramon.dexter »

The zdoom wiki pretty clearly covers ACS...

https://zdoom.org/wiki/ACS
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: I don't get ACS

Post by Gez »

Here's how I would do it:

Code: Select all

#library "REGEN"
#include "zcommon.acs"

script 2 ENTER
{ 
	while (true)
	{
		if (GetActorProperty (0, APROP_HEALTH) < 50)
		{
			HealThing(1,50);
		}
		delay(35);
	}
}
The script is run as an infinite loop ("while true" construction). The script checks the player's health and heals them if needed. Then it delays for one second before doing the next loop (always put delays in infinite loops).
Post Reply

Return to “Scripting”