Changing a texture or changing an object with a trigger

Post your scripting questions / solutions here

Moderator: Moderators

Ramah Palmer
Warrant Officer
Posts: 131
Joined: Sun May 25, 2003 10:13 am
Location: Nottinghamshire: UK

Changing a texture or changing an object with a trigger

Post by Ramah Palmer »

Hi all. I really dunno what I'm doing with scripting at all yet so I'm not sure how easy or hard this question is for you all. I did a quick search and only found one topic about chaning a texture but it wasn't really answered.
What I want is a large rectangular brush like a projector screen, and a switch that will change what is on the screen like a slideshow. Every press of the switch needs to display another texture until it loops back round to the start again.
So I guess my first thought is how can I make a brush change it's texture in a script?
If that is not feasible, is it possible to have a stack of script objects all the same shape and all at the same offset hidden and each press of the switch makes a new one visible and the last one invisible?
As I say, I'm completely new to scripting and am not sure what is really possible.
Thanks for any help you guys can offer me.
Mapping is just INCREDIBLY time consuming.
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

you cant directly change textures, but what you CAN do is make script objects out of each 'slide', and just hide and show them appropriately during the level. like this:

Code: Select all

$slide1 show
wait 4
$slide1 hide
$slide1 playsound //some sort of clicking sound
$slide1 waittill sounddone
$slide2 show
Ramah Palmer
Warrant Officer
Posts: 131
Joined: Sun May 25, 2003 10:13 am
Location: Nottinghamshire: UK

Post by Ramah Palmer »

Ok, thanks, I can see the gist of that m8. So I just keep extending your code for however many script objects I have.
But I still got a couple of questions... :D
As I say, know nothing about scripting but I do know a little about programming. If I'm gonna be using a switch with this and not just an auto-looping slideshow, shouldn't there be some kind of check to see which object is currently being displayed before hiding and showing? Otherwise won't it simply stop at the first one every time? Or go through the whole list and only display the last one?
And another question, whereabouts should this go in my script? I get very confused about things going before prespawn, or spawn etc.
And last thing - somewhere in the script I should imagine I need to have an initialising bit where all the script objects are hidden except the first one. Presumably this will need to go in a different place to the main piece of the script?
Thanks.
Mapping is just INCREDIBLY time consuming.
Ramah Palmer
Warrant Officer
Posts: 131
Joined: Sun May 25, 2003 10:13 am
Location: Nottinghamshire: UK

Post by Ramah Palmer »

K, I've sorted out the initialising bit now.
Now I think I just need a bit of help with the script code from the view of using a switch to cycle through each script object.
Mapping is just INCREDIBLY time consuming.
Ramah Palmer
Warrant Officer
Posts: 131
Joined: Sun May 25, 2003 10:13 am
Location: Nottinghamshire: UK

Post by Ramah Palmer »

Is there a command I can use to see if a script object is being shown?
E.g. if $blank_screen SHOWN then
$blank_screen hide?

And can I use curly brackets to group commands together into a kind of single statement?

e.g. (using the above example)

if $blank_screen SHOWN
{
$blank_screen hide
$screen2 show
}

I've read Bjarne's scripting tutorial but it doesn't really go into a lot of the basic nitty gritty for a complete scripting newbie like me.
Mapping is just INCREDIBLY time consuming.
Ramah Palmer
Warrant Officer
Posts: 131
Joined: Sun May 25, 2003 10:13 am
Location: Nottinghamshire: UK

Post by Ramah Palmer »

Ok, so new idea (for me anyway). Would it be best if I set up a variable to count every time the switch is pressed? And then depending on what value is stored in the variable I can show and hide the relevant objects?
Is this the best way to do it?
Mapping is just INCREDIBLY time consuming.
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

yeah right under waittill prespawn (when the level finishes loading), you can add something like this:

Code: Select all

level waittill prespawn //theres the prespawn

$slide1 hide
$slide2 hide
$slide3 hide

level.projector[shown] = "none" //can be "none" or the name of the slide shown.
level.projectornum = NIL //this will store the number

//now do all kinds of code here, and after "end", paste this thread.

changeslide:

    self playsound //put a nice beeping sound here... self is the trigger
    if (level.projector[shown] = "none") //if "none" of the slides are shown
    {
        //then start with the first slide
        $slide1 show
        level.projector[shown] = $slide1 //remember, we're setting up the variable so that it shows "none" or the name of the slide shown... in this case, $slide1.
        level.projectornum = 1 //slide 1
    }
    else //a slide is currently shown
    {
        //make an array to keep memory of the slide names
        //by using this way, we can make the script do simple math to determine what slides to show
        level.slide[1] = $slide1
        level.slide[2] = $slide2
        level.slide[3] = $slide3

        local.shown = level.slide[level.projectornum] //level.slide and then the number it is. local.shown is the slide currently shown

        local.shown hide //bye bye slide
        
        if (level.projectornum == 3) //3 is our highest number, so go to 1
        {
            level.projectornum = 1
        }
        else //so its 1 or 2
        {
            level.projectornum++ //increase by 1
        }
        
        level.slide[level.projectornum] show //this is the next slide
        end //end this thread

I hope you understood it.. :D
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

as arrays are automatically made from entities with the same targetname, ($) not level.*** / local.***

have all the slides called $slide

then script

level waittill prespawn
$slide hide
level waittill spawn
level.slide_count = 1
thread slideshow //if this is being triggered elsewhere in the map, remove this line
//and replace in the trigger have
key: setthread
value: slideshow

end

slideshow:
$slide[level.slide_count] hide
wait .1
level.slide_count++
if (level.slide_count > $slide.size)
{level.slide_count = 1}
$slide[level.slide_count] show
wait 3.9
goto slideshow //and this line and replace it with end

//this will work for any number of slides :D
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

Yeah, but how will he know which slide is which?
Ramah Palmer
Warrant Officer
Posts: 131
Joined: Sun May 25, 2003 10:13 am
Location: Nottinghamshire: UK

Post by Ramah Palmer »

Ok, thanks for the replies guys. Alcoholic, I'll possibly come back to your reply in the future but for now I'm gonna question Nuggets as you must admit - it looks a lot easier for someone new to scripting!
After reading it about three times I think I get everything you mean but I have a question (and it is probably the same question in a round about way that Alcoholic has just asked). If the slides are all called $slide how will the script differentiate between one slide and another?
Should the slides not be called something like $slide[1] and $slide[2] or is this done automatically and internally when objects have the same name?
I want the slides to be in a certain order. Does that mean I have to make and name them '$slide' in the order I want to appear? If not how, as Alcoholic said, will I know which slide is which?
Sorry again but as I say, I'm new to this. :oops:
But on the plus side I DO understand the scripts you two have given me. You guys must have been doing this for quite some time.
Mapping is just INCREDIBLY time consuming.
Ramah Palmer
Warrant Officer
Posts: 131
Joined: Sun May 25, 2003 10:13 am
Location: Nottinghamshire: UK

Post by Ramah Palmer »

Dammit. After just saying I understand it all I re-read it and notice the line at the top that I seem to have read and forgotten. You've already answered one of my questions.

as arrays are automatically made from entities with the same targetname, ($) not level.*** / local.***

So the only thing I can think of to do is name the slides '$slide' in the order I want them shown. Is this correct?
Mapping is just INCREDIBLY time consuming.
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

I don't know how it gets the order, try it.

If you have 3 things named $slide, then in the script:


//If you wanted to call all 3 at once
$slide hide

//If you wanted to call the first one spawned
$slide[1] hide
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Tutorial map

Post by tltrude »

The script does not have to be that fancy. Here is a tutorial map you can try. It has five slides, although one is just blank. The trigger is in the projection room windows. The zip contains the map file, a dm playable pk3, and a text version of the script.

http://pages.sbcglobal.net/tltrude/Temp ... heater.zip

Image

Here is the script:

Code: Select all

main:

	level waittill prespawn

	thread slideshow_prep

	level waittill spawn

end

slideshow_prep:

	$slide_1 hide
	$slide_2 hide
	$slide_3 hide
	$slide_4 hide
	thread slideshow

end

slideshow:

	$change_slide_trigger waittill trigger
	$projector_speaker playsound slide_advance 
	$slide_blank hide
	$slide_1 show
	wait 1

	$change_slide_trigger waittill trigger
	$projector_speaker playsound slide_advance 
	$slide_1 hide
	$slide_2 show
	wait 1

	$change_slide_trigger waittill trigger
	$projector_speaker playsound slide_advance 
	$slide_2 hide
	$slide_3 show
	wait 1

	$change_slide_trigger waittill trigger
	$projector_speaker playsound slide_advance 
	$slide_3 hide
	$slide_4 show
	wait 1

	$change_slide_trigger waittill trigger
	$projector_speaker playsound slide_advance 
	$slide_4 hide
	$slide_blank show
	wait 1

	goto slideshow

end
Tom Trude,

Image
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

when you make something in radiant, it is given a model number *28 or whatever it is, the map is read in this order so the 1st item you create will be the 1st slide, 2nd item 2nd slide, etc...

i don't know what tom's put in the .zip file as it requies d/loading, but if that's the way ur going, only glad to help in the little way i did :D

otherwise the script i made will work for any number of slides, as the $slide.size event checks the number of entities with that name
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

order

Post by tltrude »

I have noticed that when I add a new entity to a map it is then listed as "entity 1" in the .map text file, and all the other entities are renumber. So, the oldest entity ends up with the highest number. But, I don't know how the game numbers entities in an array, so maybe you are right nuggets. I don't think he is going to have all that many slides because he would have to include the image and shader files for all of them in his final pk3. My tutorial map uses images from the credits texture folder and a new shader I made for them.

My script (the slideshow part) is under the screenshot.
Tom Trude,

Image
Post Reply