View topic - Mod Question Repository... Questions come in, answers go out



All times are UTC + 1 hour


Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1168 posts ]  Go to page Previous  1 ... 54, 55, 56, 57, 58, 59  Next
Author Message
PostPosted: 21 Oct 2010, 13:40 
Spring Developer

Joined: 01 Jun 2005, 10:36
Location: The Netherlands
zwzsg wrote:
The name of the signal doesn't matter at all. However it's very important that each signal is a power of 2 distinct from other signals (Do you speak binary? Ever worked with bitfields?)

Code:
local function my_script()
    SetSignalMask( a_custom_signal_to_kill_the_myscript_tread  )
    Signal( a_custom_signal_to_kill_the_myscript_tread  )
    Spring.Echo('Executing my script')
end
You inverted Signal and SetSignalMask. You want to kill previous instance of my_script, not yourself! And don't forget to assign some 2^n number to a_custom_signal_to_kill_the_myscript_tread.

Then what I'm saying is from Cob, I assume it's the same for Lua unit scripts but I never tried.

That works, but in recent versions of Spring you can also use any Lua object for your signals. That way you can simply set each signal to a unique empty table object, allowing for an unlimited amount of signals (instead of only 24).

Essentially if you use this you can see SetSignalMask as setting the name of the thread and Signal stopping all the threads with the given name.


Top
 Offline Profile  
 
PostPosted: 22 Oct 2010, 11:58 
User avatar

Joined: 19 Aug 2009, 15:09
Location: Sol 3
I've been using CarRepairs Bos to Lua coverter, to see if i could make some of my own models work on a Lua script.
My aim was to make a nanotower so i converted such a script and to see if it would result in anything useful (for a noob like me).
Although i don't understand most of it, I made some changes and hope it will work.

Now my problem:
Bos...
Code:
while( Static_Var_2 != currentstate )

...converts into Lua
Code:
while  Static_Var_2 not = currentstate  do

But this line doesn't seem to be valid.
I now think that if i fix this line, the script might just work. But I can't figure what it should be. What should this line look line in Lua?
(A reference to what it actually might do, and how that should be noted down, will also be appreciated.)


Top
 Offline Profile  
 
PostPosted: 22 Oct 2010, 12:12 
Kernel Panic Co-Developer
User avatar

Joined: 16 Nov 2004, 13:08
Replace
Code:
not =
by
Code:
~=
Also tell CarRepairer to update his Bos2Lua


Top
 Offline Profile  
 
PostPosted: 22 Oct 2010, 12:19 
User avatar

Joined: 19 Aug 2009, 15:09
Location: Sol 3
Oh, i tried that. like this:
Code:
while  (Static_Var_3 ~= currentstate) do

Guess the problem lies somewhere else.
Tanks anyway.


Top
 Offline Profile  
 
PostPosted: 22 Oct 2010, 12:35 
Kernel Panic Co-Developer
User avatar

Joined: 16 Nov 2004, 13:08
FireStorm wrote:
A reference to what it actually might do, and how that should be noted down, will also be appreciated.


In C and Bos:
Code:
while(a!=b)
{
   blah;
}



In Lua:
Code:
while a~=b do
   blah
end


Where blah can be a big bunch of code several lines long.

If a and b are equal, this does nothing. If a and b are different, this execute blah, over and over and over, until a and b become equal. You'd better make sure there's something in blah that change a and b, and eventually make them equal, or else you'll be stuck in an infinite loop and your Spring application will freeze. Or another way is to exit the loop with a break or a return.




FireStorm wrote:
Guess the problem lies somewhere else.
Maybe you have an error message? Read it.
For Bos/Cob Scriptor will tell you at least the first line that had an error.
For Lua, check your infolog.txt
Well, unless it's an infinite loop problem. Then you won't have a nice error message, just Spring freezing. And recently was added the hang detection thing, which will fill your infolog with unreadable dump in that case.

Either way, describe the symptom, post the whole script, post infolog.


Top
 Offline Profile  
 
PostPosted: 22 Oct 2010, 14:47 
User avatar

Joined: 19 Aug 2009, 15:09
Location: Sol 3
the elaborate feedback is greatly appreciated, although in my script I am not (yet) bothered by complicated logic, because i haven't really touched that after conversion, afaik.
I think my current problems are still more in the area of understanding the syntax and Spring-specific things.

Spring now does accept my script; it shows some of the animations in it.
But the model still doesn't act as a nano (and infolog does not reference to any errors). Perhaps something in my animation prevents the copied and converted part to work.

But a more obvious thing i can't get right is the Reclaim-button showing up in the UI. I think i added all the relevant tags to the unitDef-file, so i was wondering:
Does the script has to work properly to make the button show up in game?
Or perhaps my script doesn't work because of the (or a different) reason it doesn't show?


Top
 Offline Profile  
 
PostPosted: 22 Oct 2010, 16:33 
Cursed Zero-K Developer
User avatar

Joined: 07 Nov 2007, 21:48
Location: Horse
FireStorm_ wrote:
I've been using CarRepairs Bos to Lua coverter, to see if i could make some of my own models work on a Lua script.
My aim was to make a nanotower so i converted such a script and to see if it would result in anything useful (for a noob like me).
Although i don't understand most of it, I made some changes and hope it will work.

Now my problem:
Bos...
Code:
while( Static_Var_2 != currentstate )

...converts into Lua
Code:
while  Static_Var_2 not = currentstate  do

But this line doesn't seem to be valid.

Fixed. It should now convert != to ~=. In the future please PM me if you know a certain line of bos is not converting properly (I see you aren't quite familiar with lua so I understand that in this case you wouldn't have known).


Top
 Offline Profile  
 
PostPosted: 22 Oct 2010, 16:50 
User avatar

Joined: 19 Aug 2009, 15:09
Location: Sol 3
Quote:
In the future please PM me if you know a certain line of bos is not converting properly

If I encounter and recognise, i will.


Top
 Offline Profile  
 
PostPosted: 26 Oct 2010, 14:46 
User avatar

Joined: 19 Aug 2009, 15:09
Location: Sol 3
I feel stuck again so i feel inclined to ask some potentially embarrassing and nooby questions:

How do i make my unit unpack into to its operating position after it is finished being build?
Code:
local function open_up()
     -- here are some callouts that make for an unpacking animation
     -- seems to works fine btw
end

function script.Create(unitID)
   open_up()
end

This code makes my unit unpack while it is still being build.
How can/should it change it to accomplish the desired behaviour?
(Is there perhaps some sort of internal CreateFinished Callin?)

(Of course i have more trouble, but one step at the time. :-) )


Top
 Offline Profile  
 
PostPosted: 26 Oct 2010, 15:04 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
Traditionally in BOS this is done with a while loop and
Code:
get BUILD_PERCENT_LEFT

So you can either use
Code:
Spring.UnitScript.GetUnitValue(COB.BUILD_PERCENT_LEFT)

or, preferably use the LuaRules API and use
Code:
select(5, Spring.GetUnitHealth(unitID))


Top
 Offline Profile  
 
PostPosted: 26 Oct 2010, 17:08 
User avatar

Joined: 19 Aug 2009, 15:09
Location: Sol 3
Time and effort for feedback is always appreciated but, I think i'll have to embarrass myself some more, because i really want my (future) models to work.

I have no real programming background, I look a Lua tutorials and i think i understand them. But it doesn't teach me what it exactly should look like in a Spring-lua-unit-script.

I know that if i write this down...
Code:
function script.Create(unitID)
   open_up()
end

...it starts when the unit (finished being build or not) turns op in game, an then this open_up stuff happens. This creation of a unit and other callins are clear triggers to me. But otherwise i still have to learn.

I understand that if i check if there is build percent left, the unit is not finished, and i can use that. But how? How do i translate that into a condition?


Top
 Offline Profile  
 
PostPosted: 26 Oct 2010, 18:17 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
You need to use a while loop and the Sleep() function e.g.

Code:
function script.Create(unitID)
  while (select(5, Spring.GetUnitHealth(unitID)) ~= 1) do
  -- I don't recall if this is 1 or 0
    Sleep(500)
  end
  open_up()
end


That will check every 500ms if the unit is fully built and do nothing until it is.


Top
 Offline Profile  
 
PostPosted: 26 Oct 2010, 20:31 
User avatar

Joined: 19 Aug 2009, 15:09
Location: Sol 3
I first copied from your reply but that didn't work. I tried a lot of combinations that i though might make sense, but no luck.
Then i saw "GetUnitValue(COB.BUILD_PERCENT_LEFT)" in a unit script from the cursed, and i got how it can be used.
Code:
function script.Create( unitID )
   while GetUnitValue(COB.BUILD_PERCENT_LEFT) > 0 do
     Sleep(500)
   end
   open_up()
end

Anyway. tanks FLOZi for pointing me in the right direction.


Top
 Offline Profile  
 
PostPosted: 26 Oct 2010, 23:50 
Cursed Zero-K Developer
User avatar

Joined: 07 Nov 2007, 21:48
Location: Horse
FireStorm_ wrote:
I first copied from your reply but that didn't work.

Please try Flozi's code again but replace
Code:
function script.Create( unitID )

with
Code:
function script.Create( )

and let us know if it works. unitID should be pulled from outside the scope of that function, so putting it as a parameter is breaking the code.

Using the lua health function is better than using the COB.


Top
 Offline Profile  
 
PostPosted: 27 Oct 2010, 00:43 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
CarRepairer wrote:
FireStorm_ wrote:
I first copied from your reply but that didn't work.

Please try Flozi's code again but replace
Code:
function script.Create( unitID )

with
Code:
function script.Create( )

and let us know if it works. unitID should be pulled from outside the scope of that function, so putting it as a parameter is breaking the code.

Using the lua health function is better than using the COB.


Good catch.


Top
 Offline Profile  
 
PostPosted: 27 Oct 2010, 10:42 
User avatar

Joined: 19 Aug 2009, 15:09
Location: Sol 3
CarRepairer wrote:
let us know if it works

Code:
function script.Create( )
   while (select(5, Spring.GetUnitHealth(unitID)) ~= 1) do
     Sleep(500)
   end
   open_up()
end

Works fine. :-)


Top
 Offline Profile  
 
PostPosted: 28 Oct 2010, 18:26 
User avatar

Joined: 19 Aug 2009, 15:09
Location: Sol 3
I have a unit (and to help visualise my problem i'll just say:) witch looks like 4 baskets close together, and the unit can transport up to 4 apples.
I have specified a point to attach an apple to, but then, not surprisingly, they all attach to that point, and all apples are in one basket.
(i tried specifying more points :-) , but then it just picks the first one.)

Of course I'd like all the apples to end up in a separate basket.
(And unload all the apples at once, but that's no problem.)

So i thought perhaps i can make the specified point change to another point, after something was picked up.
perhaps something like this:
Code:
   
   if (slot1full == false) then
    trans = linkpoint1
   slot1full = true
   end

    if (slot1full == true) then
    trans = linkpoint2
   slot2full = true
   end
   
   if (slot2full == true) then
    trans = linkpoint3
   slot3full = true
   end
   
   if (slot3full == true) then
    trans = linkpoint4
   end

   --with this:

function script.TransportPickup ( passengerID )
   UnitScript.AttachUnit(trans, passengerID )
end


Or is that a bad approach? I also tried this:
Code:
function script.TransportPickup ( passengerID )
   
   StartThread( pick_up )
   
   if (slot1full == false) then
    UnitScript.AttachUnit(linkpoint1, passengerID )
   slot1full = true
   end
   
   if (slot1full == true) then
    UnitScript.AttachUnit(linkpoint2, passengerID )
   slot2full = true
   end
   
   if (slot2full == true) then
    UnitScript.AttachUnit(linkpoint3, passengerID )
   slot3full = true
   end
   
   if (slot3full == true) then
    UnitScript.AttachUnit(linkpoint4, passengerID )
   slot1full = false
   slot2full = false
   slot3full = false
   end
   
   StartThread( stop )
end


I'm find myself not skilled enough to figure this out on my own in reasonable time. (or at all)
So once again i hope someone can be kind enough to supply some advise, or a reference to something that might help me.
(and be advised, i'm still learning... :-) )


Top
 Offline Profile  
 
PostPosted: 28 Oct 2010, 20:12 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
I'd do something like:

Code:
local baskets = {}
local numBaskets = 4
local currBasket = 1

for i = 1, numBaskets do
  -- this assumes you have pieces basket1, basket2 etc
  baskets[i] = piece ("basket" .. i )
end

function script.TransportPickup ( passengerID )
  Spring.UnitScript.AttachUnit(baskets[currBasket], passengerID)
  currBasket = currBasket + 1
  if currbasket > 4 then currBasket = 1 end
end


No guarantees on plug and play. :P


Top
 Offline Profile  
 
PostPosted: 29 Oct 2010, 17:44 
User avatar

Joined: 19 Aug 2009, 15:09
Location: Sol 3
Took me some time before it worked. Mea culpa; I changed some stuff and i didn't do that correctly.
Figuring out what was wrong did help with understanding Lua and programming though. Yeey! :-) . So, thanks.

Next challenge is keeping my transport unit from starting a transport while doing the pickup animation. Now it runs 4 pickup animations sort of concurrently, while the objects-to-be-transported are attached with almost no time in between.

1)Could someone refer me to an example or provide advise how this might/can be fixed?

Challenge after that is keeping the unit from transporting while not in range, and move towards the target instead, until it is in range and then start transporting (but I'll save that one for now) :-)

Also i was skimming over the morph gadget, and i was wondering: Why is it so long? Isn't it mainly a matter of replacing a units appearance with the appearance of another unit? I imagined that not much more complicated than replacing a unit with another unit.

2)What is it the morph gadget does behind the scenes?


Top
 Offline Profile  
 
PostPosted: 29 Oct 2010, 19:04 
Lobby Developer
User avatar

Joined: 25 Sep 2006, 12:56
may I suggest to let this obnoxious thread to die and start using instead http://answers.springlobby.info ?
this thread is really unmanageable, and a pain to search any previous answers because of the lack of tags and cathegorization:/


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1168 posts ]  Go to page Previous  1 ... 54, 55, 56, 57, 58, 59  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.