Programming question for prototype development, flow control & conditional statements

Started by
2 comments, last by Snaked 1 year, 9 months ago

I'm working on conceptualizing a game idea to eventually prototype it and I have a question on the logic of it. The game idea will be something akin to a visual novel kind of game so it will be reliant on conditional statements to handle the flow control of segments. Is it possible to over rely on nested statements and method calls when scripting segments with different branches depending on player input? I'm concerned that I might over rely on nested statements when there might be better methods of achieving similar results.

Justin Sanders

Advertisement

JustinSand11299 said:
Is it possible to over rely on nested statements and method calls when scripting segments with different branches depending on player input?

No. (I assume you talk about implementing the branching story with a sequence of if else, or switch statements.)

But that's not how games, or realtime applications in general work.

Imagine we display some multiple choice dialogue option. Seemingly nothing happens to the game until the player clicks a button.
But that's not true. We need to render the graphics, animate the mouse pointer, play audio clips, and some other stuff multiple times per second. And we could not render the graphics while we wait for a button press.
A typical game loop may look like this:

UpdateGame ()
{
	GetUserInput();
	UpdateGameLogic(); // <- we need to implement our story here
	UpdatePhysicsSimulation(); // e.g. if it was an action game
	PlayAudio();
	RenderGraphics();
	// ...
}

Notice this runs 60 times per second, so we can not process the whole story from start to finish by executing a single function implementing it with a sequence of branches.

You need something like a state machine, tracking the current state of story in it's data, basically so we can interrupt and continue story execution to alternate this with doing other tasks on our list.

if you thinking in something like a “visual Novel” in wich one you have different choices at different points of the game you have to make a file or Database file or even in someclass of variables array into the EXE program in wich one you can “track” the correlation of some parts that conduit to other ones

for example

DB File / Variables array

chapter origin (int) – choice value (int) — chapter destiny (int)

------------------------------------------------------------------

1 ------------------- 1 ----------------------- 5

1-------------------- 2 ----------------------- 3

1-------------------- 3 ----------------------- 2

then if you check this DB file following some indications into the game like chapter origin and choice value (that is what the user select in a dialog of options at some part of the gameplay) you have that for chapter origin 1 and choice 1 the resulting “jump” is chapter destiny 5 and then for go there have a Switch or something for depending of chapter destiny obtained go there through a function or something in the game flow

example:

GetUserChoice();

GetDestinyfromDBFileorWhatever();

functionforChapter1()

{

switch(choice)

{

case 1: go_Chapter5();

break;

case 2: go_Chapter3();

break;

case 3: go_Chapter2();

break;

}

}

This topic is closed to new replies.

Advertisement