permenantly set line's texture to a closed switch

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!)
Post Reply
violgamba
Posts: 41
Joined: Wed Apr 10, 2024 4:53 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10

permenantly set line's texture to a closed switch

Post by violgamba »

I have a script that is run each time a player uses a certain line-def that is textured to a switch. The script either prints "You don't have the right key" or it opens a door (if you have the key). If it opens the door, it remembers this (via a global var) so that subsequent calls print "The gate is already open."

Meanwhile, the line's texture flips to the closed switch for a second, then back to the original texture EVERY time it's used. Here's my question...

I'd like to have the script set the activation line's texture to the closed switch permanently when it successfully opens the door. I'm not sure of how to do this. I've tried the "SetLineTexture" function, but the line's texture still switches back to open switch after a second.

Thanks for any help you can provide with this.
User avatar
Enjay
 
 
Posts: 27070
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: permenantly set line's texture to a closed switch

Post by Enjay »

Normally I would suggest removing the special from the switch line and setting the texture to be the closed version. However, you actually still want the switch to do something. So, my suggestion is make a duplicate texture that looks like the closed version, but don't define it as a switch, then use that on the line once the action is complete.
violgamba
Posts: 41
Joined: Wed Apr 10, 2024 4:53 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10

Re: permenantly set line's texture to a closed switch

Post by violgamba »

Thanks for this solution! It worked... sort of. The best I version of this solution I discovered was to put the SetLineTexture(<non-registered open switch texture>) statement just before Print(s:"The gate is already open.") statement. SetLineTexture doesn't seem to prevent the switch texture swapping logic, which keeps updating the textures even if they've been changed. If I put the above statements together, though, you never see the closed switch texture once the gate is opened. The only real drawback is that you still HEAR the close switch sound effect, even though the graphic doesn't change.
Last edited by violgamba on Fri Apr 19, 2024 2:11 am, edited 1 time in total.
boris
Posts: 776
Joined: Tue Jul 15, 2003 3:37 pm

Re: permenantly set line's texture to a closed switch

Post by boris »

User avatar
SPZ1
Posts: 388
Joined: Wed Aug 02, 2017 3:01 pm
Location: Illinois
Contact:

Re: permenantly set line's texture to a closed switch

Post by SPZ1 »

First of all you're going to want to specify a Line ID and activation for the switch in a map editor.
Then, on the map's OPEN script you need to set the Line's special to a script like this : SetLineSpecial(1, 80, 2);
Now Line ID 1 runs script 2 when used.
In script 2, you're going to change the texture and check for the key like this:

Code: Select all

bool doorOpened = FALSE;

script 02 (void){
   SetLineTexture(1, SIDE_FRONT, TEXTURE_BOTTOM, "SW1DOWN");

   if ( CheckInventory("OrangeKey")){
      if (doorOpened){
         PrintBold(s:"The gate is already open");
         Terminate;
      } else {
         PrintBold(s:"You have the orange key!");
      }

      Door_Open(3, 24, 0);
      doorOpened = TRUE;
   }else{
      PrintBold(s:"You don't have the orange key!");
      Delay(35 * 2);
      SetLineTexture(1, SIDE_FRONT, TEXTURE_BOTTOM, "SW1UP");
   }

}
violgamba
Posts: 41
Joined: Wed Apr 10, 2024 4:53 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10

Re: permenantly set line's texture to a closed switch

Post by violgamba »

@SPZ1 - I ended up replacing the switch with explicit texture management. However, your code is very similar to what mine used to be. Maybe I'll revisit this and try your solution out at some point. Thanks!
Post Reply

Return to “Scripting”