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: 22309
Joined: 13 Jan 2005, 00:46

Can someone explain what script signals are?

Post by smoth »

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.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Can someone explain what script signals are?

Post by FLOZi »

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
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth »

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?
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Can someone explain what script signals are?

Post by Erik »

You could of course kill your scrips manually.
For example having a looping script check a condition etc.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Can someone explain what script signals are?

Post by Kloot »

LUS signal masks do not have to be numbers.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth »

What else can they be?
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: Can someone explain what script signals are?

Post by PicassoCT »

In technical info, using bitmasks is quite neat.. i dont see why this is troublesome.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Can someone explain what script signals are?

Post by FLOZi »

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

Re: Can someone explain what script signals are?

Post by smoth »

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.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: Can someone explain what script signals are?

Post by PicassoCT »

why, you can end multiple threads by knowing the hexadecimal killerconstant.. its comfy
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth »

except that you have to be really careful which ids you use. that makes it cumbersome. Want to add a new id? have fun.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Can someone explain what script signals are?

Post by zwzsg »

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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth »

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.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Can someone explain what script signals are?

Post by zwzsg »

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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth »

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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth »

I see, I went over it with Kingraptor. I get it now.
User avatar
Das Bruce
Posts: 3544
Joined: 23 Nov 2005, 06:16

Re: Can someone explain what script signals are?

Post by Das Bruce »

Please post a brief description of the solution.

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

Re: Can someone explain what script signals are?

Post by smoth »

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.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Can someone explain what script signals are?

Post by FLOZi »

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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Can someone explain what script signals are?

Post by smoth »

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

Return to “Game Development”