Is this a bug or quirk in RandomPick()?

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!)

Is this a bug or quirk in RandomPick()?

Postby XASSASSINX » Wed Jan 12, 2022 10:17 am

Hello folks, while testing something in Slade, i've found something interesting about RandomPick using the A_CustomBulletAttack function. Here's what i found and i wish to know if this intended or not:

I made (or rather, customizing) a 40 hitscan bullets attack, and my idea to make it more consistent while using the vanilla 5*random(1,3) damage parameter, was to use randompick with the following line of code:

Code: Select allExpand view
TNT1 A 0 A_FireBullets(14, 8, 40, randompick(5, 10, 10, 15), "NewBulletPuff", FBF_NORANDOM);


But here is the quirk, randompick seems to be picking a number and applying it TO EVERY iteration of this function. So the damage ALWAYS is coming out as 200, 400 and 600. It NEVER delivers anything else. Nothing on the wiki states this behavior, so i'm a bit confused here, isn't RANDOMPick suppose to pick a random value for every iteration? And if this is the intended way, how could i fix this to make the damage a bit more consistent?

Thanks!
XASSASSINX
 
Joined: 20 Dec 2016
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Is this a bug or quirk in RandomPick()?

Postby KeksDose » Wed Jan 12, 2022 10:40 am

RandomPick is just another function, and it gets resolved entirely before A_FireBullets does. That means you get one result, and it will be used for all bullets in A_FireBullets. You can get 40 bullets with random damage each by calling A_FireBullets 40 times.

Code: Select allExpand view
TNT1 A 0 {
   for(int ii = 0; ii < 40; ii++) {
      A_FireBullets(14, 8, 1, randompick(5, 10, 10, 15), "NewBulletPuff", FBF_NORANDOM);
   }
}


Like sooooo or by screaming TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAetc at your code if you like that.

edit: i forgot to change the 40 to a 1 so i nearly made you shoot 40 bullets 40 times lelel
Last edited by KeksDose on Wed Jan 12, 2022 10:48 am, edited 1 time in total.
User avatar
KeksDose
Praise Mima and the Moon
 
 
 
Joined: 05 Jul 2007

Re: Is this a bug or quirk in RandomPick()?

Postby Caligari87 » Wed Jan 12, 2022 10:43 am

RandomPick is only called once in this case, and sending its value to the A_FireBullets damage calculation. Or put another way, you can't send a function into another function, only a value. RandomPick is selecting a random value to pass as the damage parameter into A_FireBullets.

I'll try to clarify because I imagine this can be a little confusing.

What you're thinking is supposed to happen:
Code: Select allExpand view
randompick(5, 10, 10, 15) * 1 bullet
randompick(5, 10, 10, 15) * 1 bullet
randompick(5, 10, 10, 15) * 1 bullet
randompick(5, 10, 10, 15) * 1 bullet
...


What's actually happening:
Code: Select allExpand view

A_FireBullets(14, 8, 40, randompick(5, 10, 10, 15), "NewBulletPuff", FBF_NORANDOM);
// becomes                          |
A_FireBullets(14, 8, 40,            5             , "NewBulletPuff", FBF_NORANDOM);

5 * 1 bullet
5 * 1 bullet
5 * 1 bullet
5 * 1 bullet
...


EDIT: Keks explained it better than me I think.

8-)
User avatar
Caligari87
User Accounts Assistant
 
Joined: 26 Feb 2004
Discord: Caligari87#3089
Github ID: caligari87

Re: Is this a bug or quirk in RandomPick()?

Postby XASSASSINX » Wed Jan 12, 2022 11:05 am

Yep, that's what i thought was the "quirk" here. That's interesting. Thanks Caligari (and Keks, lol)! I will try to use Keks solution up there and credit it on the code, since it is ZScript after all.
XASSASSINX
 
Joined: 20 Dec 2016
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Is this a bug or quirk in RandomPick()?

Postby XASSASSINX » Wed Jan 12, 2022 1:15 pm

Like sooooo or by screaming TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAetc at your code if you like that.


I actually tried to do this right now, and it seems horizontal and vertical spread breaks with A_FireBullets if you do this. There is no vertical and horizontal spread. Even if i try to do something like this:

Code: Select allExpand view
TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_FireBullets(random(-14, 14), random(-8, 8), 1, randompick(5, 10, 10, 15), "NewBulletPuff", FBF_NORANDOM);
XASSASSINX
 
Joined: 20 Dec 2016
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Is this a bug or quirk in RandomPick()?

Postby Jarewill » Wed Jan 12, 2022 1:31 pm

That's how A_FireBullets works:
Wiki wrote:If numbullets is 1 and this is the first bullet fired in the Fire (not Hold) sequence, the bullet is fired with perfect accuracy, ignoring the specified spread

To make single bullet calls be affected by accuracy, you have to change amount of bullets from 1 to -1.
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: Is this a bug or quirk in RandomPick()?

Postby XASSASSINX » Wed Jan 12, 2022 1:34 pm

Oh yeah, there's that from the chaingun and pistol too. Oops. Thanks Jarewill!
XASSASSINX
 
Joined: 20 Dec 2016
Location: MURICAA BROTHER! Just kidding, Brazil.


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests