Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • 0
IronLich86

SetUserVaaaaaaaaaaar

Question

Hello everyone!
Could someone explain to me how A_SetUserVar works?
I've been reading in ZDoom Wiki, but I still do not understand how it works.

Share this post


Link to post

6 answers to this question

Recommended Posts

  • 0

sorry for answering late

I have read the User variable page but I still do not understand it at all.
I would like to know what the symbols are for <, >, ==, ++, --

I leave two examples writing down my doubts


ACTOR SpecialZombieMan : ZombieMan
{
    var int user_rockets;

    States
    {
    Spawn:
        POSS A 0 NoDelay
        { // See anonymous functions.
            user_rockets = 5;
        }

    Idle:
        Goto Super::Spawn

    Missile:
        POSS E 10 A_FaceTarget
        POSS F 8
        {
            If(user_rockets > 0)         <--(this is that if it reaches 0 it can no longer shoot more missiles?)
            {
                A_CustomMissile("Rocket");
                user_rockets--;            <--(what does -- ?)
            }
            Else
            {
                A_PosAttack;
            }
        }
        POSS E 8
        Goto See
    }
}

--------------------------------------

var int user_mad;
    
    states
    {
    See:
         TNT1 A 0 
        TNT1 A 0 a_jumpif(User_mad>=1,"See2")            <--(what does >=1 ?)
        CDW2 ABC 8 A_Chase
        TNT1 A 0 A_jumpifinventory("CacoSafety",4,"Vuln")
        CDW2 FED 8 A_Chase
        TNT1 A 0
        Loop
        See2:
        CDW2 ABCFED 5 A_Chase
        loop
    Vuln:
        CDW2 K 3
        CDW2 L 3 a_pain
        TNT1 A 0 A_changeflag("Nopain",false)
        TNT1 A 0 A_changeflag("Invulnerable",false)
        TNT1 A 0 A_changeflag("MissileEvenMore",true)
        TNT1 A 0 A_setuservar("User_mad",user_mad+1)    <--(what does user_mad+1 ?)
        TNT1 A 0 A_setspeed(24)
        CDW2 M 3  
        Goto see
    Missile:
               TNT1 A 0
        TNT1 A 0 a_jumpif(User_mad>=1,"Missile2")
        TNT1 A 0 A_Jump(255,"Handy","Bloody")
        TNT1 A 0
        Goto see
    Missile2:
        TNT1 A 0
        TNT1 A 0 A_Jump(255,"Handy2","Bloody2","portal","spikes")
        TNT1 A 0
        Goto see

 

 

thanks for the answer!

 

Share this post


Link to post
  • 0
32 minutes ago, MyArchvile said:

I would like to know what the symbols are for <, >, ==, ++, --

< and > are mostly used in conjunction with the equivalent (=) symbol in scripts, but not always.

> is greater than.

< is less than.

>= is greater than or equal to.

<= is less than or equal to.

== is equal to.

!= is not equal to.

++ means add.

-- means subtract.

So, all of these are used with variables, which you can brush up on using the links scifista provided.

When using variables, it is best when you initialize the variable to define its starting point like so:

int x=0
int y=52
int z=16

Here, x is defined as 0, so x++ will make x equal 1. Y is defined as 52, so y-- will make y equal 51. Z is defined as 16, so you can use an expression like:

script "X Z Equivalency Script" OPEN
{
 if (x>=z)
 {
  terminate; //Do nothing, because the objective has been completed.
 }
 else
 {
  x++;
  Delay (35); //One second
  Restart;
 }
}

Likewise, you can use y-- to make y equal z.

Now for a couple other answers in code.

ACTOR SpecialZombieMan : ZombieMan //Copied from the ZDoom Wiki. --AC
{
    var int user_rockets; 	//Here is the user variable.

    States
    {
    Spawn:
        POSS A 0 NoDelay
        { // See anonymous functions.
            user_rockets = 5; 	//This defines the variable as 5.
        }

    Idle:
        Goto Super::Spawn

    Missile:
        POSS E 10 A_FaceTarget
        POSS F 8
        {
            If(user_rockets > 0) 	//This means that the below attack will be called if user_rockets is 1 or greater.
            {
                A_CustomMissile("Rocket"); 	//So, the zombieman fires a rocket because user_rockets was greater than zero.
                user_rockets--; 		//This subtracts one from the variable user_rockets. If this was called with user_rockets at 5, it would now be 4.
            } 		//At 1, user_rockets would be subtracted to 0, so it would not pass the if statement anymore.
            Else 	//With user_rockets now at 0, only this attack can be called.
            {
                A_PosAttack;
            }
        }
        POSS E 8
        Goto See
    }
}

The other example will be explained here:

actor ShockWaveDoomImp : DoomImp replaces DoomImp //Also copied from the ZDoom Wiki. --AC
{
  var int user_theta;
  states
  { 	//Note that unlike the previous, the variable user_theta is not defined in the spawn state, which would be bad if we were using C, but we're not, so it's okay. It's set to zero by default.
  Missile:
    TROO EF 8 A_FaceTarget
    TROO G 0 A_SetUserVar("user_theta",0) 	//This sets user_theta to zero before calling the attack.
  Shock: 	//Intentional fall through so the missile state goes straight into the shock state.
    TROO G 0 A_CustomMissile("DoomImpBall",32,0,user_theta) 	//This causes the A_CustomMissile command to account for user_theta in the projectile's horizontal angular offset.
    TROO G 0 A_SetUserVar("user_theta",user_theta+1) 	//This increase the angle by 1 degree.
    TROO G 0 A_JumpIf(user_theta==360,"EndShock") 	//Once user_theta reaches 360, which here is 360 degrees, it goes to the endshock state.
    Loop 	//Causes the shock state to loop until user_theta equals 360.
  EndShock: 	//This is the point at which the super imp finishes launching its attack.
    TROO G 6 	//Since the shock state is looped until user_theta equals 360, this means that A_CustomMissile was called 360 times, each with a slightly different angle, so the imp throws 360 fireballs in a circle around itself.
    Goto See
  }
}

Hope that all helps.

Share this post


Link to post
  • 0
1 hour ago, Aquila Chrysaetos said:

++ means add.

-- means subtract.

More precisely:

 

++ means increment (add 1)

-- means decrement (subtract 1)

 

I suggest reading something like this or that. The operators in ACS and ZScript are basically the same as those used in C/C++.

Share this post


Link to post
  • 0
On 6/9/2018 at 11:20 PM, Aquila Chrysaetos said:

Wow! Thank you!
The truth has helped me a lot, now I understand it better.
This is difficult for someone who does not have much programming knowledge. I have only used the programming for doom, and only simple things.


I have tried to imitate the action of the mana cube that is on top of the heresiarch when it enters attack mode.
The cube starts turning slowly, then accelerates and then stops completely. Finally turns slowly again.

 

    var int user_angle;
    var int user_count;
    
    States
    {
    Spawn:
//        SBMP ABCDEFGHIJKLMNOP 2 Bright
//        TNT1 A 0 A_SpawnItemEx("Cube1", SXF_SETMASTER)
    See:
//        TNT1 A 2
//        TNT1 A 0 A_jumpifinventory("ForCube", 1, 17)
        SBMP ABCDEFGHIJKLMNOP 2 Bright
        {
            A_Warp(AAPTR_MASTER, 28, 0, 110, user_angle, WARPF_ABSOLUTEANGLE | WARPF_NOCHECKPOSITION | WARPF_INTERPOLATE);
            A_SetUserVar("user_angle", user_angle+8);
            A_SetUserVar("user_count", user_count+1);
            If(user_count > 40)
            {
                A_SetUserVar("user_angle", user_angle+10);
                If(user_count > 80)
                {
                    A_SetUserVar("user_angle", user_angle+6);
                    If(user_count > 120)
                    {
                        A_SetUserVar("user_angle", user_angle-24);
                        If(user_count > 200)
                        {
                            A_SetUserVar("user_count", user_count-200);
                        }
                    }
                }
            }
            Else
            {
            }
        }
        Loop
//        TNT1 A 0 A_SetUserVar("user_count", user_count+1)
        Goto See
 

 

I do not know if it's well done, but I got what I wanted to prove.


Thank you for your help!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×