Script problem


(stephanbay) #1

Hello fellas,

I have a script that display a repeated message during the game. Now this script works perfectly when i enable it show the message. but when i try to stop it. it does not.



mess
{
spawn 
{
accum 0 set 0
}

on
{
accum 0 set 1
trigger mess showmsg
}

off
{
accum 0 set 0
trigger mess showmsg
}

showmsg
{
accum 0 abort_if_not_equal 1
wm_announce "yes yes yes"
trigger mess showmsg
}

}


can you help me please.

thank you in advance


(Flippy) #2

instead of “showmsg” you need “trigger showmsg”

you might also need a “wait 300” in the spawn scriptblock before setting the accum value

it should work like this:


mess
{
spawn
{
wait 300
accum 0 set 0
}

on
{
accum 0 set 1
trigger mess showmsg
}

off
{
accum 0 set 0
trigger mess showmsg
}

trigger showmsg
{
accum 0 abort_if_not_equal 1
wm_announce "yes yes yes"
trigger mess showmsg
}

}

(im assuming ofcourse that you have a button or something that trigger
“trigger mess on” and “trigger mess off” ?


(stephanbay) #3

ok sorry i just typed the script manually here on the forum instead of copying and pasting here is my script. and its not wroking :(. i think its a logical problem. of course i have a button working and set up correctly (it show me the Activated and deactivated text).


mess 
{ 
spawn 
{ 
wait 250 
accum 0 set 0 
} 

trigger on 
{ 
accum 0 set 1 
wm_announce "Button Activated" 
trigger mess showmsg
} 

trigger off 
{ 
accum 0 set 0 
wm_announce "Button deactivated"
trigger mess showmsg 
} 

trigger showmsg 
{ 
accum 0 abort_if_not_equal 1 
wm_announce "yes yes yes" 
trigger mess showmsg 
} 

}

the trigger showmsg keep looping even when the trigger off is called


(Chruker) #4

When you hit the disable button. Does it then stop spamming, in the console?


(stephanbay) #5

nope. the mssage keep spamming


(Chruker) #6

But does it stop after a while (like 5 min)?

I just wanna rule out that the script is looping so fast and piling up the output. So that when you eventually hit the deactivate button, there is so much output in the pipeline that it keeps coming for a while.


(kamikazee) #7

To check Chruker’s claim, open the console. Just type /echo this and see if messages still pop up in the console.


(Flippy) #8

i dont know if this will solvet the problem but you might want to try adding wait 10 or 20 or something short after “wm_announe “yes yes yes”” (before you trigger the message again)

just for information, what kind of entity is “mess” ?


(Chruker) #9

I did some digging.

First of all my game crashes when the loop starts. It simply repeats itself to death within a fraction of a second. However adding a wait like Flippy says, solved that.

2nd, in my test map I had 2 target_script_trigger. However the damn game crates two different scriptblocks. One for each entity. Both named mess. From this point on the game gets confused and sets the accum to 1 in one scriptblock and to 0 in the other. I wonder if something is wrong here. The game shouldn’t really create a new scriptblock if one existed with the same name. Anyhoo…

To fix your endavour. Name the scriptname of the two target_script_trigger’s mess_on_button and mess_off_button and then do two new scriptblocks in your script:

mess_on_button
{
	trigger on {
		trigger mess on
	}
}

mess_off_button
{
	trigger off {
		trigger mess off
	}
}

(kamikazee) #10

Each entity has it’s own callstack and it’s own set of accums. No way to get around it. This means that two different entities sharing the same scriptname run the script in two instances.

Results of this can be seen in maps like mp_beach, where the messages are printed twice.


(Loffy) #11

I would place a func_timer (or whatever they are called) in the map, that triggers a script constantly. This script will either print the text or not depending on the button (on/off).


(stephanbay) #12

thank you getns for your solutions. im gonna try it out now and get back to you.


(stephanbay) #13

mess_on_button 
{ 
   trigger on { 
      trigger mess on 
   } 
} 

mess_off_button 
{ 
   trigger off { 
      trigger mess off 
   } 
}

I tried this solution but i get a weird problem. when i trigger mess_on_button (or off) i get a g_scripting error : trigger has unknown name : mess .
I checked and rechecked and rechecked and i m sure the script block of “mess” do exist but it just cant find it.


(S14Y3R) #14

lol, hows it goin ppl. “yes yes yes” keeps looping because its recalling itself over and over.

trigger showmsg
{
accum 0 abort_if_not_equal 1
wm_announce "yes yes yes"
trigger mess showmsg  <-----take this out so it only calls once from trigger on/off
} 

should be:

trigger showmsg
{
accum 0 abort_if_not_equal 1
wm_announce "yes yes yes"
} 

:wink:


(Chruker) #15

stephanbay:
I forgot to mention that you need a new entity in the map. Say an info_notnull which has the scriptname mess. Actually you could also keep the on button target_script_trigger as mess, and then just have a seperate scriptblock for the off button.

S14Y3R:

lol, hows it goin ppl. “yes yes yes” keeps looping because its recalling itself over and over.

That is what he wanted to do. However when the accum is set back to 0, he wanted it to stop (and stop calling itself).


(stephanbay) #16

Thanks Chruker for your reposnses. The new Info_notnulll solved the g_scripting error. Now the on and off triggers works . It shows the wm_announce “Button activated” but the showmsg script is not called, for unknown reason once again . No display or looping. Any other suggestion? lol


(Chruker) #17

Can you post the entire script as it is now?


(stephanbay) #18

IT WOOOORKS FINALLY. im dumb. forget to type “trigger” before mess showmsg. THANKS A LOT guys. you are the best.


(S14Y3R) #19

D’oh!
kk, if its supposed to stay on[and_toggle], try like Loffy said with a func_timer. they can be turned on/off via alertentity [targetname] I guess the func_timer[started off] would have to target your target_script_trigger [mess], . Yea, so in “mess_on_button” have an alertentity to trigger the func_timer looping every 5000ms? heh heh, i’m a bit rusty, but yea, func_timers can be toggled.

…I think a target_print entity[rtcw ent’s in et] does print global? maybe the [toggled]func_timer could target a target_print?

kewl,
v57!