[poll] Behaviour of piece function in LUS
Moderator: Moderators
[poll] Behaviour of piece function in LUS
[13:51:46] <[S44]FLOZi> who thinks that piece should just return nil in LUS if the model does not have that piece rather than throw an error?
[13:52:46] <[LCC]jK> make it print a LOG.ERROR
[13:52:55] <[S44]FLOZi> atm there's no easy way to check if a piece exists other than using main API functions like GetUnitPieceMap
[13:53:11] <[S44]FLOZi> i would prefer it is just nil and leave it to the gamedev to check
[13:53:20] <[LCC]jK> bad
[13:53:23] <[S44]FLOZi> no
[13:53:24] <[S44]FLOZi> good
[13:53:25] <[LCC]jK> always print errors
[13:53:27] <[S44]FLOZi> No
[13:53:49] <[S44]FLOZi> 1 script is no longer for 1 unit
[13:54:01] <[S44]FLOZi> we need a neat way to detect if a unit has such a piece
[13:54:12] <[S44]FLOZi> what is neater than it being nil
[13:54:49] <[LCC]jK> add a: ispiece""?
[13:55:45] <[S44]FLOZi> so you get "local foo if ispiece ("foo") then foo = piece("foo") end
[13:55:49] <[LCC]jK> it's always better to not hide debug messages, cause you can be sure ppl will run in errors then
[13:55:54] <[S44]FLOZi> instead of just local foo = piece ("foo")
[13:56:26] <[LCC]jK> no first you will encapsule many of those
[13:56:55] <[S44]FLOZi> fine I'll just go edit unit_script in my own game and let everyone else suffer this inanity
[13:57:01] <[LCC]jK> 2nd you can use: local foo = ispiece"foo" and piece"foo"
[13:58:13] <[S44]FLOZi> still ugly
[13:58:28] <[S44]FLOZi> this is as stupid as 'unit costs very little metal!' warning
[13:58:49] <[LCC]jK> doesn't matter as long as it prevents user errors
[13:59:02] <[LCC]jK> it's the job of a language to prevent errors from the start
[13:59:44] <KingRaptor> it throws an error if the game tries to perform an operation on a nil piece, I think that's more than enough to identify the problem
[14:00:18] <[LCC]jK> noobs need 2days first to find out that the piece is nil
[13:52:46] <[LCC]jK> make it print a LOG.ERROR
[13:52:55] <[S44]FLOZi> atm there's no easy way to check if a piece exists other than using main API functions like GetUnitPieceMap
[13:53:11] <[S44]FLOZi> i would prefer it is just nil and leave it to the gamedev to check
[13:53:20] <[LCC]jK> bad
[13:53:23] <[S44]FLOZi> no
[13:53:24] <[S44]FLOZi> good
[13:53:25] <[LCC]jK> always print errors
[13:53:27] <[S44]FLOZi> No
[13:53:49] <[S44]FLOZi> 1 script is no longer for 1 unit
[13:54:01] <[S44]FLOZi> we need a neat way to detect if a unit has such a piece
[13:54:12] <[S44]FLOZi> what is neater than it being nil
[13:54:49] <[LCC]jK> add a: ispiece""?
[13:55:45] <[S44]FLOZi> so you get "local foo if ispiece ("foo") then foo = piece("foo") end
[13:55:49] <[LCC]jK> it's always better to not hide debug messages, cause you can be sure ppl will run in errors then
[13:55:54] <[S44]FLOZi> instead of just local foo = piece ("foo")
[13:56:26] <[LCC]jK> no first you will encapsule many of those
[13:56:55] <[S44]FLOZi> fine I'll just go edit unit_script in my own game and let everyone else suffer this inanity
[13:57:01] <[LCC]jK> 2nd you can use: local foo = ispiece"foo" and piece"foo"
[13:58:13] <[S44]FLOZi> still ugly
[13:58:28] <[S44]FLOZi> this is as stupid as 'unit costs very little metal!' warning
[13:58:49] <[LCC]jK> doesn't matter as long as it prevents user errors
[13:59:02] <[LCC]jK> it's the job of a language to prevent errors from the start
[13:59:44] <KingRaptor> it throws an error if the game tries to perform an operation on a nil piece, I think that's more than enough to identify the problem
[14:00:18] <[LCC]jK> noobs need 2days first to find out that the piece is nil
Re: [poll] Behaviour of piece function in LUS
I vote error. All occurences of this should be immediately advised to the user.
Re: [poll] Behaviour of piece function in LUS
[13:59:44] <KingRaptor> it throws an error if the game tries to perform an operation on a nil piece, I think that's more than enough to identify the problemBeherith wrote:I vote error. All occurences of this should be immediately advised to the user.
Re: [poll] Behaviour of piece function in LUS
Could do something like this:
I think
local wheel = myPiece ("wheel")
is similiar enought to
local wheel = piece "wheel"
and no editing of unit_script.lua etc
Code: Select all
local wheel = myPiece ("wheel")
--have this in a file that every script includes
local function myPiece (piecename)
--no idea if it works like that, doesnt matter
return Spring.GetUnitPieceList (unitID)[piecename]
end
local wheel = myPiece ("wheel")
is similiar enought to
local wheel = piece "wheel"
and no editing of unit_script.lua etc
Re: [poll] Behaviour of piece function in LUS
I don't use LUS or anything that mix lua and unit script, but I'd don't like throwing error and prefer handling error the softest way possible, especially in the context of SpringRTS.
Because I care more about the case where a simple user will want to try the mod after 6 month and will be met with hundred of errors due to changes in the API, than the case where the modder is creating his mod.
Because I care more about the case where a simple user will want to try the mod after 6 month and will be met with hundred of errors due to changes in the API, than the case where the modder is creating his mod.
Re: [poll] Behaviour of piece function in LUS
when you say error do you mean barf some text into info log noting the missing piece? or do you mean an actual error window?
Re: [poll] Behaviour of piece function in LUS
The former, the point is i intentionally want to be able to check if a piece is available in the neatest way possible
Re: [poll] Behaviour of piece function in LUS
you restrict the options to get your wanted outcome
Re: [poll] Behaviour of piece function in LUS
Don't quite see how.jK wrote:you restrict the options to get your wanted outcome
Other option is what? ispiece?
Re: [poll] Behaviour of piece function in LUS
nvm, I didn't read again ... ^^
thought you answered: "throw an error" instead of "print a warning"
still the poll question is subjective
thought you answered: "throw an error" instead of "print a warning"
still the poll question is subjective

Re: [poll] Behaviour of piece function in LUS
Bump.
Having started to do some LUS in S44 and learn from my mistakes in MCL's architecture...
This isn't one of them, at all. I still think this is a sensible change for base content.
Having started to do some LUS in S44 and learn from my mistakes in MCL's architecture...
This isn't one of them, at all. I still think this is a sensible change for base content.
Re: [poll] Behaviour of piece function in LUS
Can i have one error and then sylance?