tg,
i want to say that your inquiry is not being ignored but i'm failing to come up with an elegant solution thus far.
that said, the immediate issue is that when currentScenario = 1, say the user is pressing the "1" key, currentScenario immediately = 2 and the "1" key is still being pressed prompting currentScenario = 4 and Game Over, all in the same loop/immediately. i think you know that already; hence your efforts to put some space between choices but falling a little short.
this is what i have so far but previous choices are being carried over into subsequent scenarios as i CreateAdventure so i've asked for help on Discord, there.
i believe i've resolved this. see the snippet below, instead.
i rarely work with what i'm trying to do but i'm sure it can be resolved but feel free to look at the code, run it and try to follow the structure in the meantime?
otherwise, you're also creating and deleting text objects every loop which is unnecessary. once i get the structure down, i'll dig back in to account for that. until then, i'm just using Print.
again, i've never done something like this before so appreciate the challenge but did want to try and help as much as possible.
EDIT: i think i've solved the Choices issue (by setting the Array length to -1 and starting over each Scenario):
// Project: Text Adventure 1
// Created: 2024-12-14
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Text Adventure 1" )
SetWindowSize( 640,360, 0 )
SetWindowAllowResize( 1 )
// set display properties
SetVirtualResolution( 640,360 )
SetOrientationAllowed( 1, 1, 1, 1 ) // portrait, portrait2, landscape, landscape2
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
CenterWindow()
Type Choice
Option as String
Label as String
Destination as Integer
EndType
Type Scene
ID as Integer
Description as String
Choices as Choice []
EndType
GLOBAL currentScene, Adventure as Scene []
MakeAdventure()
currentScene = 1
do
Play()
Sync()
loop
Function Play()
ThisIndex = Adventure.Find(currentScene)
ThisScene = currentScene
If ThisIndex > -1
Repeat
If GetRawKeyPressed(81) then End // [Q] to Quit
Print ("[" + STR(currentScene) + "] " + Adventure[ThisIndex].Description)
`GetCharBuffer()
For x = 0 to Adventure[ThisIndex].Choices.Length
ThisChoice$ = Adventure[ThisIndex].Choices[x].Option
Print( Adventure[ThisIndex].Choices[x].Label)
If GetRawKeyPressed( ASC(ThisChoice$)) = 1
currentScene = Adventure[ThisIndex].Choices[x].Destination
Exit
EndIf
Next x
Sync()
Until currentScene <> ThisScene
EndIf
EndFunction
Function MakeAdventure()
ThisScenario as Scene
ThisChoice as Choice
ThisScenario.ID = 1
ThisScenario.Description = "You wake up in a dense forest. Paths lead north and east."
ThisChoice.Option = "1"
ThisChoice.Label = "1. Go North"
ThisChoice.Destination = 2
ThisScenario.Choices.Insert(ThisChoice)
ThisChoice.Option = "2"
ThisChoice.Label = "2. Go East"
ThisChoice.Destination = 3
ThisScenario.Choices.Insert(ThisChoice)
Adventure.Insert(ThisScenario)
ThisScenario.ID = 2
ThisScenario.Description = "You head north and find a river. Do you:"
ThisScenario.Choices.Length = -1
ThisChoice.Option = "1"
ThisChoice.Label = "1. Try to swim across"
ThisChoice.Destination = 4
ThisScenario.Choices.Insert(ThisChoice)
ThisChoice.Option = "2"
ThisChoice.Label = "2. Follow the river upstream"
ThisChoice.Destination = 5
ThisScenario.Choices.Insert(ThisChoice)
Adventure.Insert(ThisScenario)
ThisScenario.ID = 3
ThisScenario.Description = "You go east and encounter a wild bear. Do you:"
ThisScenario.Choices.Length = -1
ThisChoice.Option = "1"
ThisChoice.Label = "1. Run away"
ThisChoice.Destination = 6
ThisScenario.Choices.Insert(ThisChoice)
ThisChoice.Option = "2"
ThisChoice.Label = "2. Try to scare it off"
ThisChoice.Destination = 7
ThisScenario.Choices.Insert(ThisChoice)
Adventure.Insert(ThisScenario)
ThisScenario.ID = 4
ThisScenario.Description = "You try to swim across the river but get swept away by the current. Game Over!"
ThisScenario.Choices.Length = -1
ThisChoice.Option = "R"
ThisChoice.Label = "R Restart"
ThisChoice.Destination = 1
ThisScenario.Choices.Insert(ThisChoice)
Adventure.Insert(ThisScenario)
ThisScenario.ID = 5
ThisScenario.Description = "You follow the river and find a small village. You are safe. You Win!"
ThisScenario.Choices.Length = -1
ThisChoice.Option = "R"
ThisChoice.Label = "R Restart"
ThisChoice.Destination = 1
ThisScenario.Choices.Insert(ThisChoice)
Adventure.Insert(ThisScenario)
ThisScenario.ID = 6
ThisScenario.Description = "You run away and escape safely. You live to explore another day. You Win!"
ThisScenario.Choices.Length = -1
ThisChoice.Option = "R"
ThisChoice.Label = "R Restart"
ThisChoice.Destination = 1
ThisScenario.Choices.Insert(ThisChoice)
Adventure.Insert(ThisScenario)
ThisScenario.ID = 7
ThisScenario.Description = "The bear gets angry and chases you. Game Over!"
ThisScenario.Choices.Length = -1
ThisChoice.Option = "R"
ThisChoice.Label = "R Restart"
ThisChoice.Destination = 1
ThisScenario.Choices.Insert(ThisChoice)
Adventure.Insert(ThisScenario)
Adventure.Sort()
`SaveAdventure()
EndFunction
Function SaveAdventure()
ThisFile = OpenToWrite("adventure.txt")
For x = 0 to Adventure.Length
WriteLine(ThisFile, STR(Adventure[x].ID) +"|"+ Adventure[x].Description)
For c = 0 to Adventure[x].Choices.Length
WriteLine(ThisFile, Adventure[x].Choices[c].Label)
Next c
Next x
CloseFile(ThisFile)
OpenBrowser(GetWritePath())
EndFunction
Function CenterWindow()
X = GetMaxDeviceWidth()/2.0 - GetWindowWidth()/2.0
Y = GetMaxDeviceHeight()/2.0 - GetWindowHeight()/2.0
SetWindowPosition( X,Y)
EndFunction
and, yeah, we are going about things a little differently so you may want to read up on
Types and
V2 Arrays.
it looks like you've had AppGameKit since V1 Classic while i was a late bloomer and came in @ V2 so it's pretty much all i use.
finally, thanks for the spark in this. after 2 recent game jams, i was feeling burned out and this challenge was refreshing