RemoveMe

Post » Fri May 13, 2011 1:49 pm

I don't know where I learned this, and I think I may have learned wrong... But I was under the impression that using a RemoveMe command at the end of a script would stop the script from running ever again. So I have been using them in staged timers where the last stage calls the RemoveMe. The wiki says that calling RemoveMe in any block but an OnAdd block can crash the game. I know I have been using RemoveMe in GameMode blocks and it hasn't crashed the game, until now... I have also used it in spawned NPC scripts after calling Disable and MarkForDelete. I think this may be wrong as well.

So, (1) can someone who definitely knows, shed some light on this for me please?
And (2) while were at it, is there a way I can lookup all my scripts that have this command? I have hundreds of scripts and would like to check them and remove the RemoveMe commands if I have indeed been using them incorrectly. I think I remember someone saying there is a text lookup function in the Geck somewhere, I'll search for it in the meantime. Nevermind, I found it...
Lastly, (3) what is the best way to stop a script after it has completed its usefulness besides using some dummy variable to check against (like DoOnce), since that doesn't really stop the script? Perhaps its not even necessary as scripts don't run when the player leaves a cell anyway.

Thanks for the help............ :hehe:
User avatar
Stephy Beck
 
Posts: 3492
Joined: Mon Apr 16, 2007 12:33 pm

Post » Fri May 13, 2011 2:14 pm

1. I had always thought it was the same as removeItem selfID, but called natively from a script on it's own object.. to get something to remove itself from a container (like an npc). I'd be curious to know if I understood that incorrectly.

2. No idea

3. If I need to stop a script, usually I make it a quest script and use StopQuest QuestID on it. If an npc, usually SetActorsAI 0 does the trick.. an object just disable it. Not had any issues with this so I can't know absolutely for sure.
User avatar
Justin Hankins
 
Posts: 3348
Joined: Fri Oct 26, 2007 12:36 pm

Post » Fri May 13, 2011 3:32 pm

My use of RemoveMe was solely for efficiency. Since some of my levels can have 100+ scripts running, I thought it might improve performance a little if I stopped the ones that had outlived their usefulness. One thing I do know is that scripts still run on disabled objects unless you mark them for deletion. (I think I just answered one of my own questions with that)
User avatar
lacy lake
 
Posts: 3450
Joined: Sun Dec 31, 2006 12:13 am

Post » Fri May 13, 2011 6:46 am

I've used the following template for options menus quite a few times...
scn OptionsTokenSCPTInt iButtonInt bMessageBoxBegin GameMode	If bMessageBox		Set iButton to GetButtonPressed		If (iButton == -1)			Return		Else			Set bMessageBox to 0			If (iButton == 0)			ElseIf (iButton == 1)			ElseIf (iButton == 2)			ElseIf (iButton == 3)			ElseIf (iButton == 4)			ElseIf (iButton == 5)			ElseIf (iButton == 6)			ElseIf (iButton == 7)			ElseIf (iButton == 8)			ElseIf (iButton == 9) ; Done				RemoveMe			EndIf		EndIf	Else		Set bMessageBox to 1		ShowMessage MESG	EndifEnd
... and the 'done' button doesn't crash nor does the message pop up after the RemoveMe, so I'd have to conclude that A) RemoveMe is safe in GameMode and B) that the script stops running immediately.

Also, per another question, you can use the GECK's Edit > Find Text to track all instances of anything.
User avatar
Chenae Butler
 
Posts: 3485
Joined: Sat Feb 17, 2007 3:54 pm

Post » Fri May 13, 2011 6:40 pm

I think the critical thing i've gleaned from the wiki in the 'bugs' section is to guard the RemoveMe function so that it will only be run once, and not be able to run again while the script is spinning off into the void - otherwise it will cause a crash. So when i've used it, i've also guarded the code in the gamemode block so even if the script does run however many more frames, it does nothing - usually have a Return statement at the beginning of the gamemode block that is enabled just before performing the ReMoveMe when I want the script to end.
User avatar
Carys
 
Posts: 3369
Joined: Wed Aug 23, 2006 11:15 pm

Post » Fri May 13, 2011 6:58 am

I'm using removeme in gamemode and menumode blocks without crashes, but I'm getting some odd errors that could be related. They happen in a case where there are multiple identical objects in the player's inventory, each running a script with a gamemode block. The scripts are supposed to detect whether the player is wearing power armor, and if so, another piece of equipment is added and equipped, and the object running the script then removes itself. There's an inventory count check that's supposed to prevent more than one of these pieces of equipment from being equipped. Occasionally the check seems to fail, and two pieces of equipment will be added to the player's inventory, though only one will be equipped (possibly because two of the same item can never be equipped simultaneously, regardless of whether they have biped slots selected). When that happens, one of the calls to removeme seems to fail, and the item remains in the player's inventory. It's unpredictable though, and I'm not 100% sure where the script execution error occurs.
User avatar
Amelia Pritchard
 
Posts: 3445
Joined: Mon Jul 24, 2006 2:40 am

Post » Fri May 13, 2011 7:04 pm

I saw this in the wiki, it may pertain to your issue Imp...

If there are multiple objects of the same type in the container (it is in a stack), the object that actually gets removed may be first one in the stack instead of the one that actually called the function.

User avatar
Crystal Clarke
 
Posts: 3410
Joined: Mon Dec 11, 2006 5:55 am

Post » Fri May 13, 2011 10:42 am

I don't know where I learned this, and I think I may have learned wrong... But I was under the impression that using a RemoveMe command at the end of a script would stop the script from running ever again.
That's an interesting use of them, on NPCs/Activators etc. where RemoveMe is an invalid command it'll probably crash the script and stop it running again.

But yeah, it's used to call RemoveItem on an inventory item from within it's own script. RemoveItem Thing 1 called from within Thing's own script causes a crash, RemoveMe doesn't.
However just like calling RemoveItem, quite which instance of Thing gets removed can be unreliable.
User avatar
dell
 
Posts: 3452
Joined: Sat Mar 24, 2007 2:58 am


Return to Fallout 3