• Advertisement
  • entries
  • comments
  • views

1GAM March and new Scribe feature: calling labels by variable

Sign in to follow this  


So, I started working on my March game for One Game a Month which is going to use both my GameJolt library and Scribe. It is going to be a roguelike (coincidentally; I had decided to make it a roguelike halfway through February, before they had decided on the theme lol) based on a short story I have (almost) finished. The story has a post apocalyptic setting and revolves around a young man named Henry on a quest to find his dying father some help.

Here is a shot using placeholder art:
This is a shot of the starting map: the bunker you and your father are living in. You wake up and the power is out; you check on your father (top right bed) and he has you go check on the generator (which is obviously not in working condition, seeing as how the power is out.)

I ran into some issues with Scribe here, mainly due to the lack of support for nested conditionals and loops. I was going to try to implement them (which I've already tried before), but I decided to take a whack at implementing another feature: calling labels using the label name stored in a variable. This kind of simulates a switch statement. Here is an example: if @fatherState == null @fatherState = 0 goto @fatherState 0:LockInputSay "Henry, can you go check on the generator?"yield @someoneIsSpeaking == trueSay "Don't forget that the password is 34719"@fatherState = 1yield @someoneIsSpeaking == trueUnlockInputgoto exit 1:LockInputSay "I thought you were checking on the generator?"yield @someoneIsSpeaking == trueSay "Remember, the password is 34719"yield @someoneIsSpeaking == trueUnlockInputgoto exit exit:// Since we cannot nest conditionals or loops// we use a label.

So, the first run of the script fatherState will be null, so we set it to 0, then we jump to the label 0, run through it's commands, set the state to 1, and then jump to exit. Every run after that we will just jump straight to 1, run our commands, and then jump to exit (I know that it seems kind of redundant to put the "goto exit" right above the label since we would fall through to exit, but this way we are all set if we need to add more states.)

As a side note, this is what I would consider proper use of the yield command. When I call the Say command it creates a label, positions it at the top of the screen, makes it visible, sets the variable someoneIsSpeaking to true, and then creates a task that will set someoneIsSpeaking to false and hide the label in 3 seconds. Remember that yield is the opposite of while: it loops until its condition is false and it is best to use the condition that will cause the loop to break if the variable isn't updated. This is why I check against true; if the variable isn't set it will be null and if it is ever set, it will eventually be set to false. If we used "yield @someoneIsSpeaking != false" and the variable is never set, we'll end up with an infinite loop.

Anyway, you can now call labels using literal values or variables (obviously they have to contain a valid name.) I'm going to take another whack at implementing nested conditionals and loops, but for now this should get me by. For now I am off to try to get some more work done on the story.

I decided to sit down and focus on nested conditionals...thirty minutes later and viola, Scribe now supports them (testing nested loops at the moment.) Here's an example script: @var1 = 10@var2 = 3@var3 = 10 if @var1 > 4 if @var2 > 5 if @var3 > 6 Console.WriteLine 'All are true' else Console.WriteLine 'The first two are true' elseif @var3 > 6 Console.WriteLine 'Only the first and third are true' else Console.WriteLine 'Only the first is true'elseif @var2 > 5 if @var3 > 6 Console.WriteLine 'The last two are true' else Console.WriteLine 'Only the second is true'elseif @var3 > 6 Console.WriteLine 'Ony the third is true'else Console.WriteLine 'None are true'

And now nested loops are in: @index1 = 0 while @index1 < 3 @index2 = 0 Console.WriteLine 'Index1:' @index1 while @index2 < 3 @index3 = 0 Console.WriteLine ' Index2:' @index2 while @index3 < 3 Console.WriteLine ' Index3:' @index3 @index3 += 1 @index2 += 1 @index1 += 1

Getting both to nest properly took a bit of work now and will be a bit of work to refactor, but it is definitely a feature that was needed. Now to verify that mixed nesting works properly.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement