2015-08-04 04:54:18

I'm having difficulties with coming up with a way to perform an action that I want done. I've tried several solutions, and I'm almost positive that I'm over looking something, or over thinking this. Hopefully someone can help me out.
I'm currently working on a piece of code that creates an array of 5 randomly selected digits. The main objective is to allow the player to figure out the pattern of numbers and their sequence through trial and error, however, if they don't perform the sequence in the correct order they must restart from the beginning, and do it within a set number of seconds. The problem I am having is making the player fall within those guidelines, currently it only works witht he below code
if(player[sequenceNumber]==pattern[sequenceNumber])
{
sequenceNumber++;
//play sound that alerts the player they've found the correct number.
}
The problem with this is that as soon as the if statement finishes there's no way to know if the player went directly to the next correct sequenced number, or if they chose an incorrect number before choosing the correct one, which if they did would have caused them to have to start over from the beginning according to the plan. If any more information is required I can try and provide it. Thanks in advance.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-08-04 05:08:18

So, if i'm to understand this correctly, players guess one of a sequence of numbers, if they get it right they go to the next in the sequence, but if they get it wrong they start the whole sequence over again? If thats the case something like this might work:

pattern = [1,2,3,4,5]
sequence = 0
player_number = raw_input()
//get players number
if player_number == pattern[sequence]:
sequence += 1
//play sound that correct number is chosen
else:
sequence = 0
//play sound that wrong number is chosen, reset sequence

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2015-08-04 05:28:15

that's pretty much exactly what I have already. The problem is because it's in a loop, the sequence will never go above 0, because as soon as it does, the number stored in playerNumber is not equal to patter[sequence], and there for goes to the else clause and sets itself back to 0, and an infinit loop is formed.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-08-04 05:52:39

Ahh, ok. You should probably keep track of whether the player has inputted anything or not then, something like:

pattern = [1,2,3,4,5]
sequence = 0
player_number = None
player_number = raw_input() //get players number

if player_number != None:
{
if player_number == pattern[sequence]:
{
sequence += 1
//play sound that correct number is chosen
}
else:
{
sequence = 0
//play sound that wrong number is chosen, reset sequence
}
player_number = None
}

This way, it will only run the code if there's an answer, and then clear it and wait until a new number has been given, assuming that when you grab the player_number it doesn't wait for the player to input something.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2015-08-04 06:02:32

Pretty much what magurp said.
I ran into a more complicated version of this the other day, trying to use BGT's get_characters to type a number with arbitrary numbers of digits, in a loop with a 5ms delay between iterations. I wound up having to determine if the result of get_characters was numeric, which I couldn't find a function for in the documentation, so I had to use is_alphanumeric and is not alphabetic.

Normally, I'd use something more like your example for cheats. The issue is the range of possible inputs, but since you're working with numbers, there are only a few possible values.

(This is why events are nice.)

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2015-08-04 12:02:30

Cae, the string_is_digits function is what you are looking for. However, keep in mind that, as far as I remember, it returns 0 even if the result is not numeric. Should probably be -1 instead.
Lukas

I won't be using this account any more or participating in the forum activity through other childish means like creating an alternate account. I've asked for the account to be removed but I'm not sure if that's actually technically possible here. Just writing this for people to know that I won't be replying, posting new topics or checking private messages until the account is potentially removed.

2015-08-04 12:57:14

is there a way to quickly set an array's entire index to null without having to use a for loop? The player's number sequence is kept in an aray as well.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-08-04 13:00:42

Also, in that example, why is the if nested within the first? Wouldn't the second nest only ever even be checked if the input was none, which would cause it to never be ran due to the first nest never to be run since the value of player_number would've changed to something other than none? Maybe I'm not following something here.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-08-04 13:40:57

One other thing, due to the way the game is set up, the player's input always has something in it. This is because the player doesn't directly enter the number, but rather uses the arrow keys to select the number. I think I might be able to fix it if I make the player press enter on the number they want to enter, rather than it automaticly detecting that the player has moved, but if anybody has another way of doing this that'd be great.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-08-04 15:38:19

Having it only check when the player presses enter would make things much easier.

if(key_pressed(KEY_RETURN)) {
if(player[sequenceNumber]==pattern[sequenceNumber])
{
sequenceNumber++;
//play sound that alerts the player they've found the correct number.
}
else 
{
sequenceNumber=0;
// Let the player know they got it wrong.
}
}

In that case, sequenceNumber only changes when the player presses enter.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.