Is there a point in optimizing code beyond readability?

Choicescript games are almost purely text based and require little to no graphics, processing, or memory specs, right? Or am I wrong and I should put some focus on making everything work with as few variables as possible? I ask because I’ve found that some bigger WIPs like PoMA have some issues with loading scenes, but maybe that’s only due to connection issues that wouldn’t appear in a locally installed version of the game.

1 Like

Loading issues stem (at least in my experience) from the length of the scenes. So how many variables you have makes little difference. As for how many variables you should have: As many as the game needs.

5 Likes

Thank you. How long would you recommend a scene be? Is having too many scenes also a problem?

To the title, I’m going to say yes? Yes..no, yes. I going with yes.

I agree completely with @MeltingPenguins it really is up to you in almost every way. If need only 50, use 50. Need 500, use 500. It’s only as many as get used that you need. If you start having loading issues, you could get a little clever with having two files for one scene and do a well placed story transition.

I would agree that yes, the main reason to optimize is just so that it’s easier to read, however I stand by that yes, there is a point to optimizing code past that.

To many scenes I don’t think is a problem, I think it’s twenty at a time for cogdemos when uploading, but you can keep adding more after the first twenty.

2 Likes

All of this massively depends on what you are trying to get choicescript to do… Most writers simply won’t have an issue if going from one scene/file to another even with thousands of variables. It does start to lag noticeably though if you have a lot of nested gosub_scene calls in a row, as each time it needs to load in and parse those scenes. But note this is only an issue if there are no ‘break points’ like page_break or choice mixed in the operation flow.

So if you are trying to do something more complex and out the ‘normal’ scope of things, optimization is important, but you will likely get a more noticeable result by ‘load spreading’ than optimisation per se.

6 Likes

The most important thing is that YOU understand the code and that it is easy to use. There is no optimization needed for performance.

The one thing I have noticed is that the chapters shouldn’t be too long. I originally had chapters so huge in Retribution that it did get the game to lag at that point, at least at the demo stage. Had to cut some in two, but 100 000- 140 000 is no problem.

10 Likes

I just had to halve a chapter again, not because of lag but because of QuickTest, which (for the first time) told me that it wouldn’t run because one of my scenes was so big it might cause problems on some devices. :slight_smile:

7 Likes

A scene must be exactly 1200 words. 1201 is too many. Don’t even get me started on 1199.

You need seven scenes. The moment you add an eighth scene half the audience will burn down your house.

19 Likes

Oh no…I’ve been doing this all wrong! :joy:

1 Like

For the vast majority of CYOA style games, you’re not going to notice enough of an issue with performance to care. However, if you’re one of the few pushing text games into the more “simulator” style territory and you’ve got a lot of hot loops or heavy calculations being performed in choicescript, then yes, maybe you’ll need to start worrying about performance. But ultimately, build something that works and optimise if you find it’s not as performant as you like. Better something subpar that’s finished than over optimising something that doesn’t exist.

6 Likes

ouch, truth hurts.

6 Likes

Thank you for such a concrete answer; I’ll be sure not to upset the CYOA gods with my hubris lmao.

@Payasuo Well, even if the game can run fine with a bazillion variables, it’s still better for any programmer in the long-term to try and get good code design mainly due to the fact that doing so allows you to run code that is a lot more efficient (like doing multiple things at once for example) while also allowing you to have a more organized code , which makes things easier overall, however, the only difficulty would be figuring out how to make your code shorter and more efficient, but once you manage to do so, it’ll be of great help for your programming!

Also I don’t know how choicescript works, but if it has the option to add comments, then you should use it in case you aren’t, it help with organizing yourself with knowing which code does what.

3 Likes

True, and worth saying. But it’s also always worth saying that ChoiceScript isn’t just (or even primarily) for programmers, who already had plenty of options for writing interactive fiction. It’s a language meant to help non-progammers write these beasts.

For those of us who aren’t and will never be programmers, code efficiency is often a lower priority than readability. Multiplying variables can sometimes be more easily understood than e.g. condensing several into a single numeric range and using multireplace. Ditto for copy-pasting text rather than making heavy use of gosubs and other coding efficiency tools.

The approach that lets you write a finished game is the right approach for you, regardless of whether it prepares you for a coding career.

3 Likes

Well, in that case, then optimizing your code should depend on how much you’d be willing to continue programming other stuff or not and things like that.

1 Like