JohnsonOG
JohnsonOG

Reputation: 33

Insert text into a variable within a switch statement

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.

Upvotes: 1

Views: 79

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58981

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'
}

Upvotes: 3

Related Questions