## How do I do math with ints inside a function?

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!)
CJacobsSA
Posts: 62
Joined: Mon May 30, 2016 10:01 pm

### How do I do math with ints inside a function?

This is a pretty strange question, I'm completely new to ACS and am unsure if this is actually possible or a good way to do what I wanna do. So hopefully you folks can help! Here's the situation:

Code: Select all

``````ACTOR ScoreZombieMan: ZombieMan replaces ZombieMan
{
const int killPts   =  5;
const int killPts_x = 20;
const int multPts = 1;

States
{
Death:
POSS H 0 A_GiveToTarget("PointsMultiplier", multPts)
POSS H 0 ACS_Execute(11, 0)``````
(DECORATE)

When an enemy dies, they add their kill value and a multiplier increase to (temporary) player inventory items. These inventory items are set back to 0 at the end of the script that is executed after they do so. The multiplier has its own countdown that is reduced on a timer so that part's not relevant. Said script is here:

Code: Select all

``````script 11 (void)
{
int totalPts = CheckActorInventory(0, "Points");
int multPts = CheckActorInventory(0, "PointsMultiplier");

}``````
(SCORE.ACS)

And the problem I'm having is... with the math inside GiveActorInventory, it doesn't give the player the points. Replacing the function to give the player points with a solid number works just fine. I assume this is because "addPts * multPts" isn't a valid way to add those ints together, hence my question: If that is the case, how would I go about doing that then?
ramon.dexter
Posts: 1501
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

### Re: How do I do math with ints inside a function?

The problem is in decorate. You cannot specify this type or variables in decorate. Zscript is better for this.
CJacobsSA
Posts: 62
Joined: Mon May 30, 2016 10:01 pm

### Re: How do I do math with ints inside a function?

Hmm. How so? The DECORATE part of the script works, it gives the player "PointsToAdd" and "PointsMultiplier" on death, and executes the script (which I know is functional because the debug message still comes up and "PointsToAdd" is reset to 0). Where is it going wrong?

edit: If ZScript has a better solution, though, I'd like to hear it! Daisy chaining inventory items like this is a little cumbersome.
KeksDose

Posts: 595
Joined: Thu Jul 05, 2007 6:13 pm

### Re: How do I do math with ints inside a function?

It appears you ran into a mess with activators here. [wiki]GiveActorInventory[/wiki] treats tid = 0 as "give this to all players", while [wiki]CheckActorInventory[/wiki] doesn't seem to poll anybody in particular if tid = 0. It's certainly not the activator and there's no good reason it should be the target, either, so the factors might be 0 (try calling PrintBold on them).

I'd say calling SetActivatorToTarget and replacing CheckActorInventory with CheckInventory will do the trick.
ramon.dexter
Posts: 1501
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

### Re: How do I do math with ints inside a function?

removed - warned for post blanking
Last edited by ramon.dexter on Tue Jul 17, 2018 6:35 am, edited 2 times in total.
phantombeta
Posts: 2076
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

### Re: How do I do math with ints inside a function?

ramon.dexter wrote:The main problem is that the variables are defined incorrectly, thats why they dont work.

Basically, you have to define the variables following this:

Code: Select all

``````A user variable must be declared in an actor's code with a line of this form:

var int user_<name>;
var float user_<name>;``````
Dude, stop. You aren't helping. You clearly didn't even read their code and post.
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am