Hi,
I'm having a problem as to how I'm supposed to make sure the game is ending. Basically if the player has solved x number of puzzles then a phone will ring and the player then has to find the phone. I'm not sure how to tackle this. Below is my attempt to make it work, but it doesn't. The puzzles aren't solved in a specific order by the way.
function game_start
{
if (Puzzle_1_KIDS == true && Puzzle_2_CHICAGO == true && Puzzle_3_FUNERAL == true && Puzzle_4_SISTER == true && Puzzle_5_TWO_DAYS == true)
{
cDummy.Say("Ring! Ring!");
}
else if (Puzzle_1A_LOCKED == true && Puzzle_2A_PRINCESS == true && Puzzle_3A_PRINCE == true && Puzzle_4A_MOVIES == true && Puzzle_5A_CASTLE == true)
{
cDummy.Say("Ring! Ring!");
}}
You could maybe make an array of booleans, one for each puzzle, then do something like this
// i just a counting variable
// x number of puzzles to be completed
// y number of puzzles currently completed
// P total number of puzzles
// puzzle_complete[P] an array of booleans, one for each puzzle in the game
for (i=0;i<P;i++) {
if (puzzle_complete[ i ]==true) {
y++;
}
}
if (y>=x) {
cDummy.Say("Ring. Ring.");
}
you could then put that piece of code in a function and call it each time the player completes a puzzle. The y variable should start at zero each time you call the code.
Apologies if there's any errors in that, my coding is a bit rusty but I think its ok.
Your code logic is valid aedwards, but AGS doesn't support a for-loop, so something like this instead:
// top of script
int P = 20; // total number of puzzles
int x = 15; // must complete at least 15 puzzles to continue
int y = 0; // puzzles completed
bool puzzle_complete[]; // whether each puzzle has been completed
// game_start
puzzle_complete = new bool[P]; // initialize the array
// check for end game condition
int i = 0;
while (i < P) {
if (puzzle_complete[i] == true) {
y++;
}
i++;
}
if (y>=x) {
cDummy.Say("Ring. Ring.");
}
I would recommend using more verbose global variables to better indicate what they're used for, but I was just slightly expanding aedwards' example to show how it works in AGS.
Thanks for the answers both of you, I'll try it out. But would this work for specific puzzles? Like Puzzle 1A, 2A and so on leads to one end while Puzzle 1B, 2B and so on leads to another. Because from what I gather of the codes you posted it's x random number of puzzles, but then the phone would start ringing before the xA-puzzles has been solved.
yeah, as it stands it would be for any combination of puzzles, but you could easily alter it for what you want.
Make the array 2-D, one row for normal puzzles and one for "A" puzzles, then just count up number of completed ones separately for each row
It's not possible to make multi-dimensional arrays but one can always use two separate arrays.
Solved puzzles occurring in both ways simply need to set both array fields then.
Damn, I'd better read up a bit more on what you can actually do in AGS scripting before I give any more false solutions :S
This should work:
Global.ash
enum Puzzle {
pKIDS, pCHICAGO, pFUNERAL, pSISTER, pTWO_DAYS,
pLOCKED, pPRINCESS, pPRINCE, pMOVIES, pCASTLE
};
import bool solved[11];
import void Solve(Puzzle p);
Global.asc
bool solved[11];
void Solve(Puzzle p) {
solved[p] = true;
int i = 1, s1, s2;
while (i < 11) {
if (solved[i] && i < 6) s1++;
if (solved[i] && i > 5) s2++;
i++;
}
if (s1 == 5 || s2 == 5) {
// WIN
}
}
Now, if the player solves the puzzle involving the kids, call Solve(pKIDS); (auto-complete should provide a list of the puzzles), etc.
In the function where it says "//WIN", put whatever you want to happen if the player solved either five puzzles.
I imagine putting the Say Ring-line wont suffice because that won't have any effect on the game environment, i.e. you need to set a variable/turn on a hotspot/etc.
Thanks a lot for the answers, I'll look into it.