Is there a shorter or easier way to this?

Hello. I am currently in the beginning of developing my first game with no programming history. But i hit a wall here. If my “bare handed” attribute is 1 it is set to novice and there are 5 stages to this. But the problem is; I have 7 attributes, so, should i just copy and paste the commands renaming the attributes or is there an easier method to do this?

*if bare_handed >= 1
*set bare_handed “novice”
*goto stats
*elseif bare_handed >=2
*set bare_handed “trained”
*goto stats
*elseif bare_handed >=3
*set bare_handed “competent”
*goto stats
*elseif bare_handed >=4
*set bare_handed “proficient”
*goto stats
*elseif bare_handed >=5
*set bare_handed “master”
*goto stats

Well, I definitely can’t think of anything easier than just copy-pasting some commands and changing the names of variables. It shouldn’t take you that long.

But for readability’s sake, maybe remove all these *goto stats and replace them with a single one at the end. If it results in an error, turn the Implicit Control Flow on, something you should probably do anyway at some point.

The way you’re doing it will have everyone end up a novice – because “bare_handed >= 1” includes all the higher values.

What you’d want using this approach is “bare_handed = 1”, and so on, replacing your >= with = throughout.

Make sure you’ve got your indents right, too.

I don’t agree with chasing you to Implicit Control Flow right away…seems to me you’re at the skill level that regular CS is designed for, not the ICF shortcuts.

3 Likes

Or you could start with the highest value and go in the opposite order you’re going now.

(I’d say there might be an easier way if you’re thinking like a programmer, but I wouldn’t recommend it to anyone who doesn’t think like a programmer, so.)

I also second Havenstone about not using implicit control flow shortcuts (but that’s my programmer brain speaking so take it as you will).

1 Like

Apart from what Havenstone mentioned with needing to rejig the stats with = signs instead of >= and the indents that’s fine. You can also get rid of the “goto stats” between each one and just put it at the end to streamline it as only one will get selected. If you need to check it repeatedly just turn it into a gosub so you only need to write it out once. I don’t use *elseif in these cases as you’re asking it to check something specific each time so *if works fine.

Example

*if (bare_handed < 2)
   *set bare_handed_txt “novice”

*if (bare_handed = 2)
   *set bare_handed_txt “trained”

*if (bare_handed = 3)
   *set bare_handed_txt “competent”

*if (bare_handed = 4)
   *set bare_handed_txt “proficient”

*if (bare_handed >= 5)
   *set bare_handed_txt “master”

*goto stats


1 Like

is bare_handed that contains the number ( 1 to 5 ) is the same bare_handed that contains the description ( novice to master ) ?

I don’t think that’s gonna work,
and yes, there is another way to do it, it’s called multi-replace

just use the command below to any place where you wanna show the text description of bare_handed

@{bare_handed novice|trained|competent|proficient|master}

and with this way, you don’t need two variables to contain both the number and its description, you only need one bare_handed

because too much variables are contributing to global warming

5 Likes

Ooh, good catch. You’d either need to create different variables for the number and the description, or use multireplace to display the description like Valda suggests.

I’d suggest the former, because it’s easier for most beginner coders to do that than to learn multireplace.

PS - If you use multireplace, make sure the variable can’t go higher/lower than those five values… so create the variable at 1, not 0, and don’t have any circumstances in the game where it could go higher than 5. Your game will fail the automatic tests if multireplace doesn’t have an option for every possible value of the variable (even if it’s not a possible value at the point of the game where you’ve put the multireplace).

If that’s dauntingly hard to figure out, then just use two variables (e.g. bare_handed_number and bare_handed_display), not multireplace.

1 Like

Oh whoops, totally missed that. (Need more sleep). Would be very easy to just make it a second variable though like bare_handed_txt. (I’ll fix it above.)

Admittedly I often still use the longhanded way as I find it easier to get my head around when checking the game for bugs. For something like this with 5 different options I’d personally just write it out long hand, especially if not experienced with CS. In the end either will get the job done so OP can choose :slight_smile:

1 Like

In this particular case, yes, but generally, they do different things, and the series of if-checks is more prone to certain types of bugs, since it runs every check, so it is very much dependant on what you’re trying to do. (And that is an extremely run-on sentence, but I have a headache.)

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.