Page 1 of 1

When to use Detach()

Posted: Mon Apr 13, 2015 10:37 am
by blckfire
So, I've got a couple of scripts that are fired up after a character does some actions. Are these scripts attached to the character or are they ran separately?

The kind of script is something like this:

Code: Select all

program x

somecode....

Start_Script(":somepackage:somescript", params);

endprogram
So, is that script attached to a character and therefore needs to be detached or I don't need to worry about it? I read in the forums that normally you use detach when you're running a use script but I don't think this is the case.

Re: When to use Detach()

Posted: Wed Apr 15, 2015 1:30 am
by RusseL
Hi,
as far as i know Start_Script starting already detached script, but you can easily test it with character.attached() method, so you can see which script is attached atm.

A script is attached when you use any item and get sysmessage "you are already doing another action". So if you want to avoid it and execute any use_script 'background' use detach().

Usecase:

Code: Select all

sendsysmessage(who, "You start crafting an item....");
Detach();
// After this line you are able to use another items
sleep(10);
MakeNewItem(who.backpack, blabla, .....);

Re: When to use Detach()

Posted: Thu Apr 16, 2015 5:00 am
by blckfire
Thank you, it's pretty much how I thought it worked, I just wanted to be sure since the code I have is a bit outdated (POL96).

In my case I have a few background scripts that control some stats and effects of the player and, ofc I want the character to be able to perform other actions while these are running.