return type mismatch

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.

return type mismatch

Postby ramon.dexter » Tue Jan 02, 2018 9:04 am

Hi, I'm trying to learn some advanced things in zscript, but I'm failing...

Here's a thing that I'm trying to achieve: An actor, that would do a certain thing, when player is closer that defined amount of units (basically, the tutorials from wiki on Distance3D.

I have this chunk of code:
Code: Select allExpand view
override void Tick()
   {   
        if (target && Distance3D(target) < 128)
      {
            return ResolveState("Sucking");
        }
      return ResolveState(null);
        Super.Tick();
   }


That should make the actor jump to state "sucking", when player is closer than 128 units. But gzdoom gives me error "return type mismatch", that I clearly dont unerstand...What is wrong with this code?
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
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: return type mismatch

Postby krokots » Tue Jan 02, 2018 9:08 am

funcion Tick does not return anyting (void). Change "resolveState" to "SetStateLabel"
User avatar
krokots
 
Joined: 19 Jan 2010

Re: return type mismatch

Postby Arctangent » Tue Jan 02, 2018 9:11 am

You're trying to return a state when the Tick() function doesn't return a value at all. Which is pretty meaningless even without the error - what use is returning a state if the function calling Tick() isn't designed to use a state returned from Tick() in the first place?

What you almost certainly want is the SetState() function, which is what actually sets the actor's state.
User avatar
Arctangent
squawky
 
Joined: 06 Nov 2014
Discord: SquawkyAtan#2371

Re: return type mismatch

Postby ramon.dexter » Tue Jan 02, 2018 9:41 am

Well, using 'SetState()' in place of 'Tick()' returns error about non existent virtual function. What's wrong?
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
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: return type mismatch

Postby krokots » Tue Jan 02, 2018 9:46 am

Do you know how virtual functions work?
Anyway, for your problem, this would be a one of possible solutions:
Code: Select allExpand view
override void Tick()
{   
        if (target && Distance3D(target) < 128)
      {
            SetStateLabel("Sucking");
      }
        Super.Tick();
}


OK and as of virtual functions. You can use virtual functions provided by the Actor class, check inside gzdoom.pk3 "actor.txt" what functions are virtual. This functions can be "overriden", which means, everytime this Actor calls an particular function ( say Tick() ), it will do the overriden version. Inside you can call the "parent" function by using "Super" ( Super.Tick() ).
User avatar
krokots
 
Joined: 19 Jan 2010

Re: return type mismatch

Postby ramon.dexter » Tue Jan 02, 2018 10:04 am

OK, so I can override only functions, that are virtual? That makes things more clear now.
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
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: return type mismatch

Postby ramon.dexter » Tue Jan 02, 2018 1:11 pm

Well, I made a progress. Through I didnt used the script method by overriding any function, I managed to make it work by using the A_LookEx function. Now it work as expected.

If anyone is interested, here is sample code for a simple "sucker" anomaly/trap. I sits waiting, looks around. When it sees player, it gets activated and when player comes into defined distance, it goes into active (here 'sucking') state, where damage, etc. are defined.

Code: Select allExpand view
class suckerAnomaly : actor
{      
   EDIT:
        override void BeginPlay()
   {
      if (target && Distance3D(target) < 128)
      {
            SetStateLabel("Sucking");
        }
      else if(target && Distance3D(target) > 128)
      {
         SetStateLabel("Spawn");
      }
        Super.BeginPlay();
   }

   
   
   Default
   {
      //$Category "SOA/Anomalies"
      //$Title "Sucker"
      
      
      //+LOOKALLAROUND
      +NOGRAVITY
      +NOCLIP
      +NODAMAGETHRUST
      +FORCEXYBILLBOARD
      +FORCERADIUSDMG
      
      //renderstyle "Add";
      //alpha 0.95;
      //Monster;
      //Damage 0;
      Projectile;
      //MinMissileChance 16;
      //MaxTargetRange 320;
      Speed 0;
      radius 16;
      height 64;
      scale 0.9;
   }

   States
   {   
      Spawn:
         ASUS ABCEDFGH 6;// A_LookEx(LOF_NOSOUNDCHECK, 0, 460, 0, 360, "Sucking");
         Loop;      
      Sucking:      
         TNT1 A 0 A_PlaySound("anom/suckerSee");
         ASUC AB 6 Bright A_RadiusThrust(-178, 192, RTF_AFFECTSOURCE|RTF_THRUSTZ|RTF_NOIMPACTDAMAGE, 128);
         TNT1 A 0 A_Explode(15, 64);
         ASUC CD 6 Bright A_RadiusThrust(-178, 192, RTF_AFFECTSOURCE|RTF_THRUSTZ|RTF_NOIMPACTDAMAGE, 128);
         TNT1 A 0 A_Explode(15, 64);
         ASUC EF 6 Bright A_RadiusThrust(-178, 192, RTF_AFFECTSOURCE|RTF_THRUSTZ|RTF_NOIMPACTDAMAGE, 128);
         TNT1 A 0 A_Explode(15, 64);
         ASUC GH 6 Bright A_RadiusThrust(-178, 192, RTF_AFFECTSOURCE|RTF_THRUSTZ|RTF_NOIMPACTDAMAGE, 128);
         TNT1 A 0 A_Explode(15, 64);         
         Loop;
   
   }



}


One thing which is not clear to me is the damage, dealt by the Z-thrust. Specifically, I use a negative thrust so player gets pulled to the actor, not thrusted away. And here comes the problem - the thrust applied crushes the player.When the force is below -179, it deals no damage, yet player plays the hurt sound. When the damage is -180 or higher, player gets killed almost instantly. How do I control OR avoid the crushing damage, dealt by the negative Z-thrust?

EDIT: I added how I tried to edit it using zscript. How I returns no error, but the actor stays in Spawn state and doesn't react to players presence. What am I doing wrong?
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
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: return type mismatch

Postby krokots » Tue Jan 02, 2018 4:15 pm

Try to use ZScript functions : Thrust(double speed = 0, double angle = 0) for the XY movement and AddZ(double zadd, bool moving = true) for Z-movement. You'll need to calculate correct angle between this actor and player - use AngleTo(Actor target, bool absolute = false).

Your code in ZScript is not working, because you are overriding wrong function! Function BeginPlay() only runs once, just at the point this actor is brought to life, even before the Spawn state. You have to override Tick() here.
User avatar
krokots
 
Joined: 19 Jan 2010


Return to Scripting

Who is online

Users browsing this forum: detwelve and 0 guests