1

I'm currently making a slot machine for fun. I have this switch:

switch ($gevinst) {
    '!!!' {
        'Tillykke du har vundet 50 dollarz'
        $vundet += 50
    }                        
    '+++' {
        'Tillykke du har vundet 80 dollarz'
        $vundet += 80
    }
    '%%%' {
        'Tillykke du har vundet 150 dollarz'
        $vundet += 150
    }
    '???' {
        'Tillykke du har vundet 200 dollarz'
        $vundet += 200
    }
    '===' {
        'Tillykke du har vundet 700 dollarz'
        $vundet += 700
    }
    '&&&' {
        'Tillykke du har vundet 1500 dollars'
        $vundet += 1500
    }
    '£££' {
        'Tillykke du har vundet 5000 dollarz'
        $vundet += 5000
    }
    Default {
        if (($1 + $2 -eq '!!') -or ($2 + $3 -eq '!!')) {
            'Tillykke du har vundet 30 dollarz'
            $vundet += 30
        }
        else {
            'Desværre du tabte'
        }
    }
}

and whenever I roll !!! it will add 50 bucks to my "account".
However, I'm expanding my game by making a "History" menu button where you can see your wins and looses.

My question is, what do I do if I want a specific text to be added to a variable $History?

Example: everytime I roll !!! I get 50 dollars to my $vundet and then You have won to my $History

ps. If anyone need the whole code for an answer, then I will gladly E-mail it to you.

0

1 Answer 1

3

Just define the $History above your switch: $History = @()

Then you can add the value within your switch:

'!!!' {
    'Tillykke du har vundet 50 dollarz'
    $vundet+= 50
    $history += 'Tillykke du har vundet 50 dollarz'
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks alot! Well i is posible to add `n for new line, so everytime i win the 50 bucks it makes a new line to the $history?
$history is an array, so depending how you wan't to present the messages you should already see a new line for each entry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.