[poll] Behaviour of piece function in LUS

[poll] Behaviour of piece function in LUS

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

Post Reply

Should piece throw an error or just return nil?

Error
6
60%
nil
4
40%
 
Total votes: 10

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

[poll] Behaviour of piece function in LUS

Post by FLOZi »

[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
User avatar
Beherith
Moderator
Posts: 5134
Joined: 26 Oct 2007, 16:21

Re: [poll] Behaviour of piece function in LUS

Post by Beherith »

I vote error. All occurences of this should be immediately advised to the user.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: [poll] Behaviour of piece function in LUS

Post by FLOZi »

Beherith wrote:I vote error. All occurences of this should be immediately advised to the user.
[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
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: [poll] Behaviour of piece function in LUS

Post by knorke »

Could do something like this:

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
I think
local wheel = myPiece ("wheel")
is similiar enought to
local wheel = piece "wheel"
and no editing of unit_script.lua etc
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7047
Joined: 16 Nov 2004, 13:08

Re: [poll] Behaviour of piece function in LUS

Post by zwzsg »

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

Re: [poll] Behaviour of piece function in LUS

Post by smoth »

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

Re: [poll] Behaviour of piece function in LUS

Post by FLOZi »

The former, the point is i intentionally want to be able to check if a piece is available in the neatest way possible
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: [poll] Behaviour of piece function in LUS

Post by jK »

you restrict the options to get your wanted outcome
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: [poll] Behaviour of piece function in LUS

Post by FLOZi »

jK wrote:you restrict the options to get your wanted outcome
Don't quite see how.

Other option is what? ispiece?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: [poll] Behaviour of piece function in LUS

Post by jK »

nvm, I didn't read again ... ^^
thought you answered: "throw an error" instead of "print a warning"
still the poll question is subjective ;)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: [poll] Behaviour of piece function in LUS

Post by FLOZi »

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

Re: [poll] Behaviour of piece function in LUS

Post by PicassoCT »

Can i have one error and then sylance?
Post Reply

Return to “Game Development”

cron