The aGorm can't code well Thread
Moderator: Moderators
The aGorm can't code well Thread
OK, I'm not sure whats changed here, this all worked perfectly yesterday. For some reason, when ever I attack with this unit, it calls script.StartMoving() (I know it calls this as if I uncoment the 'Spring.Echo' that pings a message everytime I attack.) and it does so for as far as I can tell, no valid reason. The only changes I made were adding in the gadets and luas for normal maps, so I dont see how that could have screwed it up. SO, I'm guessing that at some point I deleted or added a line and didn't notice in the unit script.
code: http://pastebin.com/iWZNaJMb
Anyone see where I went wrong? Also... why do Signals have to be 1 2 4 etc...?
aGorm
knorke: made you a pastebin
code: http://pastebin.com/iWZNaJMb
Anyone see where I went wrong? Also... why do Signals have to be 1 2 4 etc...?
aGorm
knorke: made you a pastebin
Re: The aGorm can't code well Thread
It's not too unusual that StartMoving is called when you don't want it to, are you sure it wasn't being called before? Did you change the unitdef or weapondef at all?
As for signals, in cob they are bitmasks, though Tobi added something in LUS which means you can actually use any object. I imagine they still behave as bitmasks for integers though (which can be useful if you say, want one signal to kill two independent threads)
As for signals, in cob they are bitmasks, though Tobi added something in LUS which means you can actually use any object. I imagine they still behave as bitmasks for integers though (which can be useful if you say, want one signal to kill two independent threads)
Re: The aGorm can't code well Thread
StartMoving / StopMoving get called all the time in strange situations. ie if a unit is driving and decreases speed just a tiny speed to make a turn, they get called too. (imo a bug but oh well)
To decide if threadnumber A is killed by signalnumber B some bitwise operation is used. (see Flozis link)
http://pastebin.com/raw.php?i=qEPRtcD9
X means thread gets killed.
Notice most numbers kill multiple threads at once.
Now look at row 1,2,8,16: Notice there is only one X
Some numbers only kill one thread, usually those are the ones you want to use. (ie do not want to stop the recoil animation if the unit stops walking)
1,2,8,16,32,128,256,...
x^2
(disclaimer: not sure if 100% correct)
To decide if threadnumber A is killed by signalnumber B some bitwise operation is used. (see Flozis link)
http://pastebin.com/raw.php?i=qEPRtcD9
X means thread gets killed.
Notice most numbers kill multiple threads at once.
Now look at row 1,2,8,16: Notice there is only one X
Some numbers only kill one thread, usually those are the ones you want to use. (ie do not want to stop the recoil animation if the unit stops walking)
1,2,8,16,32,128,256,...
x^2
(disclaimer: not sure if 100% correct)
Re: The aGorm can't code well Thread
OK, so i found the bug.
For some reason this sleep causes it to trigger? I don't know why though. I was using it to desynce the walk cycles so large groups would look odd, (by giving them a small random delay), but I suppose I shall have to come at it another way... anyone got any good ideas how to achive somthign similar? And anyone have an explanation for why that would have been the cause?
PS thanks knorke for the paste bin, I'll start to use that from now on.
aGorm
Code: Select all
local function walk()
[color=#BF0000]Sleep (math.random(100))[/color]
Signal(SIG_WALK)
SetSignalMask(SIG_WALK)
while (true) do
PS thanks knorke for the paste bin, I'll start to use that from now on.
aGorm
Re: The aGorm can't code well Thread
try like:
(set signal first, then sleep)
Code: Select all
local function walk()
Signal(SIG_WALK)
SetSignalMask(SIG_WALK)
Sleep (math.random(100))
while (true) do
Re: The aGorm can't code well Thread
Yep... more questions for you coding gurus out there...
I have a function and I want it to call another function.
Example:
Now, I know at the moment the putting the aim code in there own functions is unessesery, as I could just put it stright in, but thats cause this is a realy simplfied version of what I want to do. What I'm wondering is, why would that not work?
aGorm
I have a function and I want it to call another function.
Example:
Code: Select all
function script.AimWeapon1( heading, pitch )
--make sure the aiming animation is only run once
Signal(SIG_AIM)
Signal(SIG_SWING)
SetSignalMask(SIG_AIM)
if heading < math.rad(180) then
AimWeapon1Left( 2, 4 )
return true
else
AimWeapon1Right( 2, 4 )
return true
end
end
local function AimWeapon1Left( headingmod, pitchmod )
--Spring.Echo ("left" + headingmod + pitchmod)
Turn(body, 2, heading, math.rad(150))
--------------------- wait
WaitForTurn (body, y_axis)
return true
end
local function AimWeapon1Right( headingmod, pitchmod )
--Spring.Echo ("right" + headingmod + pitchmod)
Turn(body, 2, heading, math.rad(150))
--------------------- wait
WaitForTurn (body, y_axis)
return true
end
aGorm
Re: The aGorm can't code well Thread
iirc WaitForX and Sleep can only be called in 'threads', i.e. functions called using StartThread. This of course results in other possible problems.
Re: The aGorm can't code well Thread
... hmmm, OK, is there some way I can include the code (IE, like in PHP you might do an include of say your page headers, so there all referencing one file? Although in this case I just want to reference a block of code elsewere in the script...)
aGorm
aGorm
Re: The aGorm can't code well Thread
Dont know if i can give any good avice here - but my attempt to solve this would be to have three diffrent walk animations, and to hand to every unit a diffrent walkanimation seed.aGorm wrote:Anyone got any good ideas how to achive somthign similar? And anyone have an explanation for why that would have been the cause?
PS thanks knorke for the paste bin, I'll start to use that from now on.
aGorm
Seeds would be generated and stored while manufacturing.
Unit with seed: 332211>>doALoop would walk diffrent (just by the looks of course) then unit with 313131.
Dont know if this is a good solution though. If every unit has such a value that is constantly called during movement, the price for moving large groups could get very high, very fast.. so i would make a safetyline that doesent use the seed when more then fifty units are selected.
TL, dr; Grab yourself Code Blocks and a Compiler, and start forking things up
Re: The aGorm can't code well Thread
are you getting a specific error? have you tried using a forward declaration?aGorm wrote:I have a function and I want it to call another function.
Code: Select all
-- forward declaration
local AimWeapon1Left, AimWeapon1Right
function script.AimWeapon1( heading, pitch )
--make sure the aiming animation is only run once
Signal(SIG_AIM)
Signal(SIG_SWING)
SetSignalMask(SIG_AIM)
if heading < math.rad(180) then
AimWeapon1Left( 2, 4 )
return true
else
AimWeapon1Right( 2, 4 )
return true
end
end
local function AimWeapon1Left( headingmod, pitchmod )
--Spring.Echo ("left" + headingmod + pitchmod)
Turn(body, 2, heading, math.rad(150))
--------------------- wait
WaitForTurn (body, y_axis)
return true
end
local function AimWeapon1Right( headingmod, pitchmod )
--Spring.Echo ("right" + headingmod + pitchmod)
Turn(body, 2, heading, math.rad(150))
--------------------- wait
WaitForTurn (body, y_axis)
return true
end
Re: The aGorm can't code well Thread
Derp, I didn't even think of the obvious issue. I'm so off the ball lately.
Re: The aGorm can't code well Thread
OK, so I worked a way around my problem... (by not trying to do it that way, I realised I was being stupid and trying to do somthing I didn't even need)
I'm wondering though... is there a limit on the number of threads in a script? Currently I have 4, will going to 5 make it slow down loads if there are many units? How about 6 or 7? Has anyone tested this?
aGorm
I'm wondering though... is there a limit on the number of threads in a script? Currently I have 4, will going to 5 make it slow down loads if there are many units? How about 6 or 7? Has anyone tested this?
aGorm
Re: The aGorm can't code well Thread
I guess eventually too much of anything is bad. But in practice it does not seem to matter much/at all.
Re: The aGorm can't code well Thread
Code: Select all
local function RestoreAfterDelay()
Signal(SIG_RESTORE)
SetSignalMask(SIG_RESTORE)
while (true) do
Sleep(RESTORE_DELAY)
aiming = 0
Turn(body, 2, 0 ,math.rad(500))
Turn(head, 2, 0, math.rad(150))
Turn(head, 1, 0, math.rad(150))
Turn(R_upper, 3, 0, math.rad(200))
Turn(R_upper, 2, 0, math.rad(200))
Turn(R_upper, 1, 0, math.rad(200))
Turn(L_upper, 3, 0, math.rad(200))
Turn(L_upper, 1, 0, math.rad(200))
Turn(L_lower, 1, 0, math.rad(200))
Turn(L_lower, 2, 0, math.rad(200))
Turn(R_upper, 3, 0, math.rad(400))
Turn(R_lower, 2, 0, math.rad(200))
Turn(R_hand, 2, 0, math.rad(200))
Turn(R_lower, 3, 0, math.rad(150))
Spring.Echo ("im restoring")
Signal(SIG_RESTORE)
end
end
Re: The aGorm can't code well Thread
It's a function, you can just use a return statement to leave it
Re: The aGorm can't code well Thread
Code: Select all
[f=0000078] WARNING: could not load model "objects3d/cybernaut_h.s3o" (missing file?)
[f=0000078] Spring 0.82.7.1 (0.82.7.1) has crashed.
[f=0000078] Exception: Access violation (0xc0000005)
[f=0000078] Exception Address: 0x007c15a1
aGorm
Re: The aGorm can't code well Thread
Did you reset the textures when re-exporting / resaving the s3o?
Re: The aGorm can't code well Thread
I was an idiot.... had changed the textures to dds, and forgot to go back though my s3o's and re name....
Now I have a very odd problem. I have to units, both using pretty much the same script. Both have a walk cycle that is identical (sharing teh same legs as they do). But for some reason I can't quite figure out, the walk on one is messed up and on the other isn't. I've been pulling my hair out and final have narrowed it down to this:
For some reason "function script.StopMoving()" keeps being called on one unit. its walking just teh same as the other one, but were as one just pings "starting to walk!" at teh start and "stopped walking!" when it reaches its destination, the second unit keeps pinging both all the time its walking (hence the walk cycle is stoped and started from the start again all the time.)
Has anyone else had a smililar issue at all? I can't help think its not so much the script but maybe somthing in the unit defs? Can you have a max-speed less than 1? Thats the only difference I think?
aGorm
Now I have a very odd problem. I have to units, both using pretty much the same script. Both have a walk cycle that is identical (sharing teh same legs as they do). But for some reason I can't quite figure out, the walk on one is messed up and on the other isn't. I've been pulling my hair out and final have narrowed it down to this:
Code: Select all
function script.StartMoving()
Spring.Echo ("starting to walk!")
StartThread (walk)
Signal(SIG_REST)
end
function script.StopMoving()
Spring.Echo ("stopped walking!")
StartThread (rest)
Signal(SIG_WALK)
StartThread(legs_down)
end
Has anyone else had a smililar issue at all? I can't help think its not so much the script but maybe somthing in the unit defs? Can you have a max-speed less than 1? Thats the only difference I think?
aGorm
Re: The aGorm can't code well Thread
yes, i had similar issues. You actually can see it in the console, the unit is stoping all the time. While Turning. While coming to a hill.. encountering friends and so on.
Trick is to make the stop thread slightly timedelayed, so when the unit starts walking again, the signal kills the stopthread before it can signal the walkthread to be killed.
Trick is to make the stop thread slightly timedelayed, so when the unit starts walking again, the signal kills the stopthread before it can signal the walkthread to be killed.
Re: The aGorm can't code well Thread
Speed is a float so that should be fine. Picasso is probably on the right track