Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[SWN] Price field on a ship shows NaN

Hi there! I just noticed the price feature on ships for Stars Without Number. When I check the box, it says "NaN". What does this mean?
1600614830

Edited 1600617785
Oosh
Sheet Author
API Scripter
This means "Not a Number" - the sheet is expecting an integer and getting something else. I'm not at all familiar with the sheet though, so I don't know why it would be doing that. edit - well I had a quick look, and the price checkbox triggers a worker that calculates the total price from adding cost of the repeating field sections (Weapons/Fittings/Defenses) and adds them to an Attribute @{ship_hull_price}. This Attribute doesn't seem to exist on the sheet - presumably it's a hidden Attribute which should be auto-filled when you select your Hull Type, but currently isn't working. If you know what your hull price should be, you can create an Attribute on the Attributes & Abilities tab, name it ship_hull_price and fill in the price yourself. Unchecking and re-checking the price box should now work - all the prices it grabs from the repeating sections seem to work. The key exists in the code: "hulltypes": { battleship: { ship_ac: "16", ship_armor: "20", ship_class: translate("CAPITAL"), ship_crew_max: "1000", ship_crew_min: "200", ship_hardpoints_max: "15", ship_hp: "100", ship_mass_max: "50", ship_power_max: "75", ship_speed: "0", ship_hull_price: "50000000", but isn't being autofilled for some reason. Someone with better javascript-fu can probably pinpoint exactly what's going wrong, and suggest a sheet fix.
Thank you very much! That fixed it right up. 
1600700411

Edited 1600700630
Oosh
Sheet Author
API Scripter
No problem... was kind of hoping GiGs would drop past with his sheet fixing magic and fix it all permanently. Maybe I wasn't shining that giant floodlight with a big ole "G" in the right direction? edit - not that he's responsible for the sheet, he's just good at getting these things done
1600707886

Edited 1600708561
GiGs
Pro
Sheet Author
API Scripter
Thanks for the praise, Oosh, but I may have to let you down here! Is this about the SWN Revised sheet? That's using minified code with all the sheet workers encoded in a single huge function. I don't touch code like that - too much chance of messing something up without understanding how it all fits together. I also think that kind of coding goes against the spirit of the roll20 github rules since it creates a level of obfuscation that makes it hard for users to contribute to that sheet's development. I dont want to help such sheets - that would be implicitly supporting such practices. Aside from raising an issue on the github, the best bet is probably contacting one of the two authors listed in the sheet json: <a href="https://app.roll20.net/users/1164773/karl-h" rel="nofollow">https://app.roll20.net/users/1164773/karl-h</a> <a href="https://app.roll20.net/users/2223776/eric" rel="nofollow">https://app.roll20.net/users/2223776/eric</a>
1600708440
Kavini
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Just an FYI: I raised this with Nighthunter on his discord.
1600709577

Edited 1600711028
Karl H.
Sheet Author
The code is minified in the root folder, but if you look in the Source folder on the official roll20 GitHub you'll find the source code very neatly laid out in (imo) a much more approachable format than a lot of sheets. At least, as approachable as I can make it with the amount of functionality that's gone in there over the years. There's also instructions for exactly what build system we use (the sheet is written in Pug in order to keep my sanity) and a whole 2 lines of command line to set it up. The "level of obfuscation" is literally "look in the source folder", I'm honestly curious how you missed that? Either way, you're welcome to peruse the source code and fix things! I would count it as a courtesy to submit it to my fork or at least let me know about it, so I don't double the work without noticing. Anyway, for the OP, this is Working as Intended – sort of. The whole ship price auto-calculation is very new, and so existing sheets don't have a lot of that information stored. I might write a migration function to look up the price and fill it in, but I have not done so. The checkbox is provided (and defaults to off) precisely because auto-calculating does not work with many sheets, and also does not currently support homebrew hull types. Again, I might get around to that. EDIT: I did find a bug, as it turns out. I'll make a note that the feature (and it's non-functionality for existing sheets) is not clear. I'll endevour to explain that better in the design. If you run into any more issues with the sheet in the future, btw, you'll reach me faster by following the link to "submit an issue" at the bottom of the sheet, which takes you to my GitHub fork. I don't get email notifications from this forum so I rely on people finding it and telling me (like Nic kindly did on the SWN community Discord just now), so I'm not as fast to respond here sadly.
Nic B. said: Just an FYI: I raised this with Nighthunter on his discord. You make it sound so grand, Nic, all I have is a channel ;)
Actually, as I looked at it, I found a somewhat subtle bug preventing the hull price from actually making its way through the filling function. I've missed the deadline for this week's update, but I'll have it submitted before next week's.
1600755556
Oosh
Sheet Author
API Scripter
Thanks Karl - what was the bug, if you don't mind a quick explanation? Currently learning some javascript basics, so I had a quick look at the function and I couldn't really see why ship_hull_price wasn't getting filled on a blank sheet when all the other values seemed to be working.
I'll give it a go! This is the function in question: const fillShipStats = () =&gt; { getAttrs ([ "ship_hulltype" , ... shipStats ] , v =&gt; { const label = v.ship_hulltype &amp;&amp; reverseHullTypes [v.ship_hulltype. toLowerCase ()] ; if (label &amp;&amp; autofillData . hulltypes . hasOwnProperty (label)) { const data = Object . assign ({} , autofillData . hulltypes [label]) ; data. ship_hp_max = data. ship_hp ; Object . keys (data). forEach (key =&gt; { //Might remove later. Unsure if desired feature. if (!([ "" , 0 , "0" ]. includes (v[key]))) delete data[key] ; //Prevents changing Hull Type }) ; mySetAttrs (data , v) ; calculateShipStats () ; } }) ; } ; And this part in particular is where the bug was: if (!([ "" , 0 , "0" ]. includes (v[key]))) delete data[key] ; //Prevents changing Hull Type This line deletes each key if it is not equal to 0 in some way (so if the list ["", 0, "0"] containes the value of one of the fields it is kept). This accidentally also deleted ship_hull_price from the autofilling data because the field for ship_hull_price does not exist on the sheet, and so is neither "", 0, or "0". The intention of this line is to prevent overwriting of values that have already been set. The fix was this: if (!([ "" , 0 , "0" ]. includes (v[key])) &amp;&amp; v. hasOwnProperty (key)) delete data[key] ; //Prevents changing Hull Type Which also requires the value to exist on the sheet in order to delete it from the autofill bundle. I also added "ship_hull_price" to the shipStats constant, to ensure it is actually passed into the above function.
1600780504
Oosh
Sheet Author
API Scripter
Ah I see, thanks for the explanation! That makes sense now.
Quick question that I'm posting here because I'm not sure if it's related to this bug or not. Operating Cost and Maintenance Cost are supposed to be filling automatically when the price is calculated or am I supposed to calculate and fill those fields manually? Thanks!
1601788780
Oosh
Sheet Author
API Scripter
I think you need to do those manually - I don't remember seeing anything in the autofill keys or the functions which would handle either of those. Could be wrong though, I don't play the game!