scripting: weird multiple executing of scriptblock [SOLVED]


(]UBC[ McNite) #1

Hey guys,

something weird happens in my map: I have an event in a script block calling a trigger, but apparently that trigger gets executed several times… as I m very sure there s no mistake in the script (see below) and also that event only gets called from another scriptblock (not by a misled trigger with some life of its own) i m a bit at a loss. Well… it won’t matter in the game with the wm_announces removed, but it still isn’t as clean as it should be.

Here comes the relevant script part:


bm // some constructible
{
	built final
	{
		setstate bm default	
		setstate bmmat invisible
		wm_announce "Axis built the Mechanism!"
		trigger bm bmbuilt // calls the bmbuilt after X secs
	}

	trigger bmbuilt
	{
		wm_announce "^1bmbuilt called"
		wait 5000
		trigger gwinner constructed
		trigger eventone eventoneon
	}
}

eventone
{

	trigger eventoneon
	{
		setstate triggeronce default //sets a trigger_once default, no diff when its _multiple with -1
		wm_announce "^1-- trigger one visible --"
		wm_announce "blablabla"
	}

	trigger triggerevent
	{
		wm_announce "^1-- triggerevent one visible --"
		trigger eventtwo eventtwoon // calls eventtwoon in other scriptblock
	}
}

So what happens is that the “trigger eventoneon” apparently gets executed 5 times which you can see in the game.
Funnily enough the “trigger gwinner constructed” initiates his block only once in the other part of the script, while both get started in the same bm block…

Any suggestions? Is this harmful? Thx for help though!

(And for the nitpickers: yea those scripts are not complete… i deleted the stuff that s not touched by the problem.)


(EB) #2

Willing to part with the map portion for further investigation ?


(Loffy) #3

I have no clue, but I would try somehting like this:


game_manager
{
   spawn
   {
   }
   
   trigger bmbuilt
   {
      wm_announce "^1bmbuilt called"
      trigger gwinner constructed
      trigger eventone eventoneon
   }
} 

eventone
{

   trigger eventoneon
   {
      wait 5000
      setstate triggeronce default //sets a trigger_once default, no diff when its _multiple with -1
      wm_announce "^1-- trigger one visible --"
      wm_announce "blablabla"
   }

   trigger triggerevent
   {
      wm_announce "^1-- triggerevent one visible --"
      trigger eventtwo eventtwoon // calls eventtwoon in other scriptblock
   }
} 


(DerSaidin) #4

Whats eventone?

Just a script, or is there brushes with it?


(2Bit) #5

Hi McNite

I think/hope I know what your problem is.

Have a look at the brushes that make up your func_constructible. If you made the whole entity by creating a part, making it a func_constructible, then duplicating those components to make the overall entity, this could result in your error.

Eg maybe you made a plank for a ramp, made it a func_constructible, then duplicated the plank a few times to complete the ramp.

If you did this, then even though all your brushes are shown as the single named func_constructible, they are actually separate constructibles with the same name, if you see what I mean. So if you made the constructible by duplicating a chunk 4 times, you’d have 5 constructibles masquerading as one. And your trigger would mysteriously execute 5 times.

What you would need to do is select all of the brushes that make up the constructible, ungroup them, then turn them back into a func_constructible all together.

I hope this helps.

:smiley:


(kamikazee) #6

Note you can allso select them all, starting from the first entity you want the others to group with.
Then right-click in 2D view and select ‘move into entity’. (or something named similar)


(2Bit) #7

I thought Move Into Entity groups the selected brushes into the last entity selected, not the first. Anyway I think it would be cleaner to ungroup the lot and create the func_constructible afresh, then there is no doubt (to you and to Radiant) that you have created a single entity.


(SCDS_reyalP) #8

g_scriptDebug might help. Be warned that it can generate a LOT of output, so you will probably want to log to a file.


(]UBC[ McNite) #9

About the problem resulting from several func_constructibles: the final constructible is 1 brush, so that cant be it. Also I had the same problem (5x exectution) while the eventoneon was called from another script part which was the delivery of a document.

2bit is right about the “move into” btw.

Ders: eventone is a scriptblock that is connected to a 1-brush entity (a trigger_once) which has scriptname and targetname “eventone”. It gets set invisible when it spawns, and gets set to default in eventoneon.

Going to check the g_scriptdebug in a few…


(]UBC[ McNite) #10

Hm, scriptdebug doesnt enhance my view of the problem… i get:

241150 : (bm) GScript event: built final
241150 : (bm) GScript command: setstate bm default
241150 : (bm) GScript command: setstate bmmat invisible
241150 : (bm) GScript command: wm_announce "blablabla"
241150 : (bm) GScript command: trigger bm bmbuilt
241150 : (bm) GScript event: trigger bmbuilt
241150 : (bm) GScript command: wm_announce "^1bmbuilt called"
241150 : (bm) GScript command: wait 5000
blablabla
^1bmbuilt called
246200 : (bm) GScript command: trigger eventone eventoneon
246200 : (sacr_onetr) GScript event: trigger eventoneon
246200 : (sacr_onetr) GScript command: setstate eventone default
246200 : (sacr_onetr) GScript command: wm_announce "^1-- trigger one visible --"
246200 : (sacr_onetr) GScript command: wm_announce "blablabla2"

And for a strange reason i GScript event: trigger eventone gets called 5 times… (another for after the one i posted in code…
I ll try a wait in there, but then i m really at a loss.

edit: its seems i have several entities calling the same GScript event: spawn… so i guess them all having the same scriptname is the nono… will check on that.


(kamikazee) #11

Ah yes. Script blocks are not shared between different entities with the same scriptname…
They behave identically, but they all have their own accums and maybe their own triggers as well, where all get called here…
I knew about the accums, never thought it could go wrong for a trigger.


(]UBC[ McNite) #12

Ok and here comes teh solution: as suspected, I had 5 entities all having the same scriptname. This obviously means that script gets intiated 5 times, and when the trigger eventoneon gets called, it gets executed in 5 scripts (which are all the same). Well… at least that s my approach to explain it…
Reducing the number of entities with the same scriptname resulted in the trigger getting executed as many times as I had entities with the scriptname… now i m down to 1 entity… all fine. It only means now i m having 5 scriptblocks where i had 1 before…


(SCDS_reyalP) #13

Yes, using the same scriptname for multiple entities is a Bad Idea.