Can someone explain what script signals are?

Can someone explain what script signals are?

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

User avatar
smoth
Posts: 22298
Joined: 13 Jan 2005, 00:46

Can someone explain what script signals are?

Post by smoth » 02 Feb 2013, 15:32

I am not really sure what they do and suspect I may have a signal related issue, so I am trying to figure out how they work and what they do.
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6107
Joined: 29 Apr 2005, 01:14

Re: Can someone explain what script signals are?

Post by FLOZi » 02 Feb 2013, 15:57

This old chestnut;

Basically its a way to kill previously called (Thread) functions.

SetSignalMask assigns a bitmask to the (Thread) function it is called from.

Every call to Signal that matches in a bitwise AND will kill the function.

e.g.

Code: Select all

function Foo()
Signal(4)
SetSignalMask(4) -- 100
-- Do Stuff
Spring.StartThread(Elmo)
end

function Foo2()
Signal(2)
SetSignalMask(2) -- 010
--Do Stuff
end

function Bar()
Signal(6) -- 110
-- Do stuff
end
Foo() and Foo2() will kill any previous instances of themselves every time they are called (this is the common pattern with AimWeapon), Bar() will kill both Foo() and Foo2(). Note that Elmo() will inherit the signal mask of the function calling it - and consequently Bar() kills Elmo() too.

See also:

http://springrts.com/phpbb/viewtopic.ph ... start=2%7C

http://springrts.com/wiki/Animation-CobThreads#Signals
0 x

User avatar
smoth
Posts: 22298
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth » 02 Feb 2013, 16:14

That is problematic. That means in order to have a 32nd weapon we would have to have a positively huge number or do I not understand this correctly?
0 x

User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Can someone explain what script signals are?

Post by Erik » 02 Feb 2013, 16:35

You could of course kill your scrips manually.
For example having a looping script check a condition etc.
0 x

Kloot
Spring Developer
Posts: 1865
Joined: 08 Oct 2006, 16:58

Re: Can someone explain what script signals are?

Post by Kloot » 02 Feb 2013, 16:38

LUS signal masks do not have to be numbers.
0 x

User avatar
smoth
Posts: 22298
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth » 02 Feb 2013, 16:45

What else can they be?
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10228
Joined: 24 Jan 2006, 21:12

Re: Can someone explain what script signals are?

Post by PicassoCT » 02 Feb 2013, 18:31

In technical info, using bitmasks is quite neat.. i dont see why this is troublesome.
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6107
Joined: 29 Apr 2005, 01:14

Re: Can someone explain what script signals are?

Post by FLOZi » 02 Feb 2013, 20:30

0 x

User avatar
smoth
Posts: 22298
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth » 02 Feb 2013, 23:50

PicassoCT wrote:In technical info, using bitmasks is quite neat.. i dont see why this is troublesome.
They are neat for smaller applications. I find the way they constrain things to be clumsy and inflexible.
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10228
Joined: 24 Jan 2006, 21:12

Re: Can someone explain what script signals are?

Post by PicassoCT » 03 Feb 2013, 00:06

why, you can end multiple threads by knowing the hexadecimal killerconstant.. its comfy
0 x

User avatar
smoth
Posts: 22298
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth » 03 Feb 2013, 00:13

except that you have to be really careful which ids you use. that makes it cumbersome. Want to add a new id? have fun.
0 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7015
Joined: 16 Nov 2004, 13:08

Re: Can someone explain what script signals are?

Post by zwzsg » 03 Feb 2013, 02:31

Just use powers of two: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, ...
smoth wrote:That is problematic. That means in order to have a 32nd weapon we would have [...]
Yes that would be problematic. TA bos/cob are limited to 32 bits signed integer, which means they must be in the range [2^31 , 2^31-1]. So you can't have a 32nd weapon. Because 2^32 would not be a positively huge number, it would be a number so huge it would overflow and come back negative.

As Kloot said, abandon BOS/COB and use Lua unit scripts.
0 x

User avatar
smoth
Posts: 22298
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth » 03 Feb 2013, 02:48

I am using a lua script. It tries to treat numbers as values for a bitwise evaluation.

if I had it my way I would do 1,2,3,4,5 as the signal id. however, it tries to handle that via bitwise. my bug with the script was because I put 515 instead of 512 which it then did the bitwise evaluation and BAM weapons were getting their signal canceled.
0 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7015
Joined: 16 Nov 2004, 13:08

Re: Can someone explain what script signals are?

Post by zwzsg » 03 Feb 2013, 03:54

As FLOZi links to TOBI posts point out : In LUS, don't use numbers, but unique empty table object, so you can have unlimited signals.
0 x

User avatar
smoth
Posts: 22298
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth » 03 Feb 2013, 04:26

This is for a generic script that covers most units. The Sig IDs ARE in a table already. so what? need to do "a","b","c"? Why can't I just use a look up table with numbers? You guys say create a table but the example I saw shows IDs being assigned some string.

the term table in lua can mean many things including but not limited to A FUNCTION.

So you are saying my signal tag can be a function? That makes very little sense to me.
0 x

User avatar
smoth
Posts: 22298
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth » 03 Feb 2013, 05:34

I see, I went over it with Kingraptor. I get it now.
0 x

User avatar
Das Bruce
Posts: 3544
Joined: 23 Nov 2005, 06:16

Re: Can someone explain what script signals are?

Post by Das Bruce » 03 Feb 2013, 06:04

Please post a brief description of the solution.

Image
0 x

User avatar
smoth
Posts: 22298
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth » 03 Feb 2013, 06:46

http://paste.springfiles.com/view/175ab271
I read this, saw that the code has some retarded kludge that if something is a number it tries to treat it as a bitwise evaluation.

complained a bit.

did this.

Code: Select all

local SIG_AIM	=	{} 

for i=1,	32 do 
	SIG_AIM[i] = {} 
end
stopped caring.
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6107
Joined: 29 Apr 2005, 01:14

Re: Can someone explain what script signals are?

Post by FLOZi » 03 Feb 2013, 13:33

Code: Select all

Signal(2 ^ (weaponID - 1))
Allows for the maximum number (32) numerical IDs.

edit:

In fact as Spring lua uses 32bit floats to represent numbers, the largest integer it can represent is 2^24, so if you wish to use more than 25 weapon IDs (don't forget 2^0) you will need to use non-numerical Signals for at least some of them.
0 x

User avatar
smoth
Posts: 22298
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth » 03 Feb 2013, 16:47

Signal checks the type of the mask var. If mask is a number, it does bitwise.
0 x

Post Reply

Return to “Game Development”