The "How do I..." Thread

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.

Re: The "How do I..." Thread

Postby MetallicaSepultura » Wed Oct 25, 2017 1:01 am

Blue Shadow wrote:I think you're using an old version of GZDoom which doesn't support anonymous functions, because I just tried the same code with GZDoom 2.1.1, and it gave me that error.

i'm using the 3.2.0 version.

aniway, i have another question. is it possible to lower a sector only when it gets hit by a rocket?
User avatar
MetallicaSepultura
Taking the Angst, setting Revenge
 
Joined: 15 May 2016
Location: Futura City, currently slaughtering Rahzs

Re: The "How do I..." Thread

Postby Apeirogon » Wed Oct 25, 2017 8:02 am

Chickenlegz wrote:
Apeirogon wrote:How make a_wander function more offen change direction of wandering?
I try angle actor with a_setangle, but that only make monster sprite spin "like record baby, round round, round round..." and dont change direction of wandering.


btw, haven't tested this, but A_SetAngle prior A_Wander with CHF_NODIRECTIONTURN as combi, perhaps it helps.
Code: Select allExpand view
Wander:
  NAME A 0 A_SetAngle(angle)
  NAME A 4 A_Wander(CHF_NODIRECTIONTURN)


if I understood your request right...

Aaand, that no works, I already try it.

I add a_setangle and thristthing after wander, and get what I need.Well, almost...

More complex thing, why when i write something like
Spoiler:

gzdoom say ""gut gut" and nods approvingly
But whe i write somethig like
Spoiler:

gzdoom cry in fear/rage "Return type mismatch!!!!11oneone"
Whats wrong with return type and why they mismatch?
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: The "How do I..." Thread

Postby Blue Shadow » Wed Oct 25, 2017 10:24 am

You need a return outside the if/else blocks.
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: The "How do I..." Thread

Postby Apeirogon » Wed Oct 25, 2017 11:52 am

But I need jump to state depending by quantity of goods in pocket, distance to enemy/monsters, health, mass, temperature, time from last call to mom, value of fine-structure constant and weather on north-east part of mars.

Or i MUST increase entropy of the univerese,and mess in the code, with something like

Spoiler:
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: The "How do I..." Thread

Postby Blue Shadow » Wed Oct 25, 2017 12:50 pm

Where did I say that you should use a series of A_JumpIfs? If your function returns a value all other returned values should be of the same data type. Also, the function must end with a return:

Code: Select allExpand view
{
    if (blah >= 0)
    {
        return state("BlahState");
    }
    else
    {
        return state("BlahState2");
    }

    return state(""); // <---
}
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: The "How do I..." Thread

Postby Apeirogon » Wed Oct 25, 2017 1:08 pm

Nowhere. I myself thought....well, suggested.

Hold on, what value and value type? String, boolean, number? My return state function must, was conceived, return one from the two string with desired state name. So data type was same.
And why I need place empty state at the end of the anon.funct.? Its abort anon.funct. Abort and the end of the function? Why?
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: The "How do I..." Thread

Postby Blue Shadow » Thu Oct 26, 2017 1:30 am

Why do you need a return at the end? Because you need to cover all paths the function could take during execution. After all said and done, the function must return something. If all fails, the only way out of the function is at its end.

The last line in the sample code I put above tells the engine to abort and go to the next state.
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: The "How do I..." Thread

Postby Apeirogon » Thu Oct 26, 2017 4:53 am

So, if I correct understand, "return" means "return (to previous bracketed part of code, which contains this function)"
And after that engine pick some state in if/else part they return to anon.funct, which must be stoped to allow jump to picked in if/else part state?!
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: The "How do I..." Thread

Postby Gutawer » Thu Oct 26, 2017 7:10 am

Return means that, yes, but it also means "Give this value to the part of the code that is calling this function". In anonymous functions, this is a State, and when writing your code, you need to make sure that every single scenario in the code is covered by the return values:
Code: Select allExpand view
if (whatever) {
    return resolveState("Blah");
}
else {
    return resolveState("Blah2");
}

This will compile, since there are only 2 scenarios - whatever is true, and whatever is false. Both of these have a corresponding return value, and the compiler is smart enough to know that there is no possible other path.

Code: Select allExpand view
if (whatever) {
    return resolveState("Blah");
}
else if (whatever2) {
    return resolveState("Blah2");
}

This won't compile, as there are 3 scenarios - "whatever is true", "whatever is false and whatever2 is true", and "whatever is false, and whatever2 is false". In the code, the 3rd scenario is beyond the else if (whatever2) {} block - therefore, it needs a return resolveState(null) to finish off the chain, otherwise it's (implicitly) returning void in a function that needs to return State - void is not a State, so that doesn't work.
User avatar
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: The "How do I..." Thread

Postby Apeirogon » Thu Oct 26, 2017 7:33 am

So, after some "else if(some_thing){something;}" compilator awaits simple "else{another_something}" and if it dont get it, it considers this as error "dont finished functions, compiler dont know what to do next", regardless of previous conditions?
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: The "How do I..." Thread

Postby UsernameAK » Thu Oct 26, 2017 7:41 am

Is there any flag that prevents bouncing on a specific linedef/flat?
User avatar
UsernameAK
Cat
 
Joined: 15 Jul 2015
Location: Ukraine
Discord: /bin/cat#8891

Re: The "How do I..." Thread

Postby BigProjectAlone » Thu Oct 26, 2017 12:08 pm

Hello, im trying to do a custom pistol that can be reloaded at any time.. Like if you decide to reload and you still have some ammo left in your clip, it will not take a full clip from your inventory. It will just fill your clip with the needed ammo.
So, i success doing all this.. the only problem is that you can still reload even if you have 0 ammo left in your inventory. It continue to fill your clip...
Giving you free ammo.. i tried, and i tried and tried, i can't find why.
So i came here to ask for a litle help, there is my gun and ammo script

LoadedBeretta = the clip in your gun
9MMAmmo = the ammo that fill your clips


If someone is able to find the problem, would be really nice, thank you!! :




Code: Select allExpand view
ACTOR Beretta: Weapon 7016
{
//$Category Weapons
  scale 0.18
  radius 15
  height 77
  Weapon.SelectionOrder 12000
  Weapon.YAdjust 15
  Weapon.ammotype Loadedberetta
  Weapon.ammotype2 9mmAmmo
  Weapon.ammogive 10
  Weapon.ammogive2 5
  Weapon.ammouse 1
  TAG "Beretta"
  Damagetype normal
  Inventory.PickupSound "PICKUPS"
  Inventory.PickupMessage "You found a 9mm Beretta"
  +noautoaim
  +float
  +nogravity
  +Weapon.AMMO_OPTIONAL
  States
  {
  Spawn:
    BRTA Z 5
    Loop
  Ready:
    BRTA A 5 A_WeaponReady(WRF_ALLOWRELOAD)
    Loop
  Deselect:
    BRTA A 1 A_Lower
    Loop
  Select:
    BRTA A 1 A_Raise
    Loop
  Fire:
    BRTA B 0
    BRTA B 0 A_JUMPIFnoammo("Noammoz")
    BRTA B 0 A_playsound("berta_f",6,127)
   BRTA B 1 bright A_FireBullets(5.6, 0, 1, 10,"bulletpuffz123",1)
   BRTA CE 1
   BRTA D 0 A_spawndebris("9mmdebris")
   BRTA D 1
   BRTA F 3
   BRTA F 3 A_refire
   Goto ready

   Reload:
    BRTA A 1 A_JUMPIFInventory("9mmammo",0,"noammoz")
   BRTA A 0 A_JUMPIFInventory("LoadedBeretta",10,"select")
   goto Loading
   
   Loading:
   BRTA A 0
   {
   if (CountInv("9mmammo") == 0)
   {
       A_jump(255,"Loadedz");
   }
   }
   BRTA A 0 A_JUMPIFinventory("Loadedberetta", 10,"Loadedz")
   BRTA A 0 A_giveInventory("LoadedBeretta", 1)
   BRTA A 0 A_TakeInventory("9mmammo",1)
    Loop

   Loadedz:
   TNT1 A 30 A_playsound("berta_r",6,127)
   BRTA AAAAAAAAAAAAA 1 A_RAISE
   Goto ready
   
   noammoz:
    BRTA X 2 A_playsound("berta_na",6,127)
   BRTA A 5
   Goto ready
   }
}





ACTOR LoadedBeretta : Ammo
{
 Inventory.MaxAmount 11
}

ACTOR 9mmAmmo : Ammo 7018
{
 scale 0.28
 Inventory.PickupSound "PICKUPS"
 Inventory.Amount 10
 Inventory.MaxAmount 100
 Inventory.Icon "CLIPA0"
 Inventory.PickupMessage "Picked up some 9mm ammo."
 States
 {
 Spawn:
  9MMA A 100
  9MMA A 0 A_SpawnItem("flash",1)
  9MMA A 13
  Stop
 }
}
User avatar
BigProjectAlone
Boss
 
Joined: 21 Mar 2012
Location: canada

Re: The "How do I..." Thread

Postby Blue Shadow » Thu Oct 26, 2017 2:13 pm

A_JumpIfInventory
ZDoom wiki wrote:Note that if amount is 0, the jump is only performed if the actor is carrying the maximum number of that item. This is useful for checking whether the player has the maximum amount of ammo for a particular weapon, regardless of whether or not he's found a backpack.
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: The "How do I..." Thread

Postby BigProjectAlone » Thu Oct 26, 2017 2:26 pm

Blue Shadow wrote:A_JumpIfInventory
ZDoom wiki wrote:Note that if amount is 0, the jump is only performed if the actor is carrying the maximum number of that item. This is useful for checking whether the player has the maximum amount of ammo for a particular weapon, regardless of whether or not he's found a backpack.


yeah but how to do jump when there is no more of it in its inventory ?
User avatar
BigProjectAlone
Boss
 
Joined: 21 Mar 2012
Location: canada

Re: The "How do I..." Thread

Postby BigProjectAlone » Thu Oct 26, 2017 4:57 pm

Nobody have an idea of what i could do to fix my problem ? =/
User avatar
BigProjectAlone
Boss
 
Joined: 21 Mar 2012
Location: canada

PreviousNext

Return to Editing (Archive)

Who is online

Users browsing this forum: No registered users and 1 guest