Issues With Global Arrays and DrawNumber

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
22alpha22
Posts: 303
Joined: Fri Feb 21, 2014 5:04 pm
Graphics Processor: nVidia with Vulkan support
Location: Montana, USA

Issues With Global Arrays and DrawNumber

Post by 22alpha22 »

I've created a range finder that works by calculating the distance between the player and a bulletpuff, then displaying the distance on the HUD via SBARINFO and a global array. The problem is that the number on the HUD always comes out as "0" and I'm not sure why.

The bulletpuff:
Spoiler:
The ACS:
Spoiler:
The SBARINFO:
Spoiler:
As you can see, the range value between the player and the puff should be displayed on the HUD whenever the player activates the scope on the weapon, but for some reason the value always comes out "0". In order to be sure the distance values were being calculated correctly, I added the following line to "Range_Finder" script.

Code: Select all

PrintBold(d:PlayerRangeFinder(GetActorProperty(0,APROP_TARGETTID)));
The result was the range to the puff was displayed with expected values in the center of the screen and logged to the console, therefore ruling out any miscalculations in the range finder function. To make matters more interesting, I have an older, more complex range finder script that was called directly from the weapon, rather than a puff, which does display the correct values on the HUD.

The older ACS:
Spoiler:
The reason I abandoned the old script, which did work correctly, was simply because it only worked when aiming at shootable things and wouldn't provide range values for stuff like level geometry. The new script should provide range values on just about everything, but for whatever reason it just wont work at all.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: Issues With Global Arrays and DrawNumber

Post by Blue Shadow »

I believe the problem is here:

Code: Select all

Script "Range_Finder" (void) {
RangeFinder[PlayerNumber()] = PlayerRangeFinder(GetActorProperty(0,APROP_TARGETTID));
} 
Since the script is called by a non-player (the puff, in this case), PlayerNumber() will return -1.
User avatar
22alpha22
Posts: 303
Joined: Fri Feb 21, 2014 5:04 pm
Graphics Processor: nVidia with Vulkan support
Location: Montana, USA

Re: Issues With Global Arrays and DrawNumber

Post by 22alpha22 »

Blue Shadow wrote:Since the script is called by a non-player (the puff, in this case), PlayerNumber() will return -1.
Thank you so much! I can't believe I overlooked that, I must have been really tired when I wrote that script. Anyway, I've given the puff a TID which is offset from the player's TID and modified the script to make the player the activator. Now it works perfectly.

Code: Select all

Script "Range_Finder" (void) {
Int PuffTID = ActivatorTID();

SetActivatorToTarget(PuffTID);
RangeFinder[PlayerNumber()] = PlayerRangeFinder(PuffTID);
}
Locked

Return to “Editing (Archive)”