define variable to use in multiple functions

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.

define variable to use in multiple functions

Postby Lagi » Sat Feb 20, 2021 7:40 am

I would like to use variable inside decorate function, but somehow it doesnt seem to work


my weapon decorate using in 8x places:
Code: Select allExpand view
A_Custompunch(random(30, 40), 1, CPF_NORANDOMPUFFZ, "StaffPuff", 80);


I want to change damage value, so i would like to use something like :

Code: Select allExpand view
int MyVar = random (30, 40);
A_Custompunch( MyVar, 1, CPF_NORANDOMPUFFZ, "StaffPuff", 80)


So after trying few things i use the Zscript to write my function. but i think its overkill. Any advise?

Code: Select allExpand view
action void punchdmg(){
 FTranslatedLineTarget t;
            double ang = angle + Random2() * (5.625 / 256);
            double pitch = AimLineAttack(ang, 64, null, 0., ALF_CHECK3D);
            LineAttack(ang, 64, pitch, random(10, 30), 'Melee', "StaffPuff", LAF_ISMELEEATTACK, t);
//A_Custompunch(random(30, 40), 1, CPF_NORANDOMPUFFZ, "StaffPuff", 80);
}


Code: Select allExpand view
SPRT A 1 punchdmg();
User avatar
Lagi
 
Joined: 23 Jun 2018
Location: Thou shalt alter thy beliefs with new evidence

Re: define variable to use in multiple functions

Postby Player701 » Sat Feb 20, 2021 8:50 am

This definitely works:

Code: Select allExpand view
action void A_MyCustomPunch()
{
    A_CustomPunch(random(30, 40), 1, CPF_NORANDOMPUFFZ, 'StaffPuff', 80);
}
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: define variable to use in multiple functions

Postby Lagi » Sat Feb 20, 2021 9:06 am

i swear to the sun i try this before

action void punchdmg()
{
A_CustomPunch(random(30, 40), 1, CPF_NORANDOMPUFFZ, 'StaffPuff', 80);
}

yes its works :D
User avatar
Lagi
 
Joined: 23 Jun 2018
Location: Thou shalt alter thy beliefs with new evidence


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests