How to give each score to each player?

Hi,

I would like to question how each player have an independent score in game.
Please see the following game.
I set one score manager device on the level and prepare the following code on verse:

prop_teleport := class(creative_device):

    @editable
    TriggerCard : []trigger_device = array{}

    @editable
    ScoreManagerDevice<public> : score_manager_device = score_manager_device{}

    OnBegin<override>()<suspends>:void=
        Playspace: fort_playspace = GetPlayspace()
        var AllPlayers: []player = Playspace.GetPlayers()
        Sleep(3.0)

        for(Index -> TriggeredCard : TriggerCard):
            spawn{CheckTrigger(TriggeredCard,Index)}

  CheckTrigger(Card:trigger_device,Index:int)<suspends>:void =
          loop:
              QAgent := Card.TriggeredEvent.Await()
              if(ToString(Index) = CardIndex):
                  AwardScore(QAgent)
                  break
              else:
                  PenaltyScore(QAgent)

    AwardScore<public>(QAgent:?agent) : void =
        set PlayerScore = PlayerScore + 1
        if(Agent := QAgent?):
            ScoreManagerDevice.SetScoreAward(PlayerScore)
            ScoreManagerDevice.Activate(Agent)
    
    PenaltyScore<public>(QAgent:?agent) : void =
       set PlayerScore = PlayerScore - 1
       if(Agent := QAgent?):
        ScoreManagerDevice.SetScoreAward(PlayerScore)
        ScoreManagerDevice.Activate(Agent)

This code means:
1, More than two Trigger Device and one Score Manager Deviced is prepared
2, Create “Await” task of Trigger Device
3, I would like to make a game that when a player shoots the right Trigger Device, plus 1 to this player. While, when he shoots the wrong Trigger Device, minus one to the player.

In other words, On this game, if more than two player join, each player should have each score.

However, with the above code, as the attached movie shows, it seems that the score of score manager device is updated by all player’s shoot and give its score to players as “AwardScore” and “PenaltyScore” method is executed. (In this video, player “KG12121” is me. My score is initially “0”. My shoot in this video hits wrong Trigger Device, so My score is updated to “-1”. However, this video shows that my score is to “-4”. Perhaps until my shoot, the score magaer device is updated by other players and the score is given to me)

I would like to have each player’s score updated independently by this player’s shoot result.
How do I revise this code and setting of the Level?

Regards,

I believe score managers are supposed to give individual score, are you sure the score in the scoreboard (opened using the show map key) is also bugged ?

I noticed that the HUD Info Box scoreboard can be random sometimes.

Thank you very much!

HUD Info Box scoreboard can be random sometimes.

I will confirm again.
Regards,

1 Like

Hi,

I tried with my two player to confirm whether it is bug.
The answer seems to be YES. I shoot with one player updating the score then shoot with another. The result that the score is also updated for both of two player. And result screen show these score, so it is a bug, I think.

The Official Document show that “Activate” method grants score to agent but this “score” is not independent with my way. Do you have other way to realize what I want to do?

Regards,



Ok you might be right but I think I found something else in your code

    PenaltyScore<public>(QAgent:?agent) : void =
       set PlayerScore = PlayerScore - 1
       if(Agent := QAgent?):
        ScoreManagerDevice.SetScoreAward(PlayerScore) # indenting is bad
        ScoreManagerDevice.Activate(Agent) # indenting is bad

It would be really strange that it comes from this but can you try to fix this ?

Maybe it’s your trigger_device that’s triggering for everybody, you could add Prints to know where it might come frome

Thank you,

Indent is a blind spot. I will try again whether it works.

Regards,

Sorry, I found the cause.

My entire code is here:

prop_teleport := class(creative_device):

    @editable
    TriggerCard : []trigger_device = array{}

    var PlayerScore : int = 0

    @editable
    ScoreManagerDevice<public> : score_manager_device = score_manager_device{}


    OnBegin<override>()<suspends>:void=
        Playspace: fort_playspace = GetPlayspace()
        var AllPlayers: []player = Playspace.GetPlayers()
        Sleep(3.0)

        for(Index -> TriggeredCard : TriggerCard):
            spawn{CheckTrigger(TriggeredCard,Index)}

  CheckTrigger(Card:trigger_device,Index:int)<suspends>:void =
          loop:
              QAgent := Card.TriggeredEvent.Await()
              if(ToString(Index) = CardIndex):
                  AwardScore(QAgent)
                  break
              else:
                  PenaltyScore(QAgent)

    AwardScore<public>(QAgent:?agent) : void =
        set PlayerScore = PlayerScore + 1
        if(Agent := QAgent?):
            ScoreManagerDevice.SetScoreAward(PlayerScore)
            ScoreManagerDevice.Activate(Agent)
    
    PenaltyScore<public>(QAgent:?agent) : void =
       set PlayerScore = PlayerScore - 1
       if(Agent := QAgent?):
        ScoreManagerDevice.SetScoreAward(PlayerScore)
        ScoreManagerDevice.Activate(Agent)

I use the same score variable “PlayerScore” every time AwardScore/PenaltyScore method are executed, this is the reason. I will revise my code, but there is another problem:

In my game, more than two player play. And AwardScore/PenaltyScore method work when Trigger Device is shoot (Score is grant to QAgent)
So, I will prepare more than two “PlayerScore” variable.

prop_teleport := class(creative_device):

    @editable
    TriggerCard : []trigger_device = array{}

    var PlayerScore : int = 0
    var PlayerScore2 : int = 0
    var PlayerScore3 : int = 0
    var PlayerScore4 : int = 0
    var PlayerScore5 : int = 0


    @editable
    ScoreManagerDevice<public> : score_manager_device = score_manager_device{}

However, the content of QAgent depends on player’s action (shoot). How should I linke “PlayerScore” variable with each player?

Please give me some advices.

Regards,

Oh yeah you’re right, I could’ve noticed for sure.

Instead of creating X variables PlayerScoreX, you could maybe use a PlayerScore : [player]int = map{}

This way you keep it cleaner and it works better upon new players joining :man_shrugging:

Thank you,

And could I ask way to use PlayerScore : [player]int = map{}?
The whole code is here:

prop_teleport := class(creative_device):

    @editable
    TriggerCard : []trigger_device = array{}

    PlayerScore : [player]int = map{(#Set Later)} 

    @editable
    ScoreManagerDevice<public> : score_manager_device = score_manager_device{}


    OnBegin<override>()<suspends>:void=
        Playspace: fort_playspace = GetPlayspace()
        var AllPlayers: []player = Playspace.GetPlayers()
        Sleep(3.0)

        for(Index -> TriggeredCard : TriggerCard):
            spawn{CheckTrigger(TriggeredCard,Index)}

  CheckTrigger(Card:trigger_device,Index:int)<suspends>:void =
          loop:
              QAgent := Card.TriggeredEvent.Await()
              if(ToString(Index) = CardIndex):
                  AwardScore(QAgent)
                  break
              else:
                  PenaltyScore(QAgent)

    AwardScore<public>(QAgent:?agent) : void =
        set PlayerScore = PlayerScore + 1
        if(Agent := QAgent?):
            ScoreManagerDevice.SetScoreAward(PlayerScore)
            ScoreManagerDevice.Activate(Agent)
    
    PenaltyScore<public>(QAgent:?agent) : void =
       set PlayerScore = PlayerScore - 1
       if(Agent := QAgent?):
        ScoreManagerDevice.SetScoreAward(PlayerScore)
        ScoreManagerDevice.Activate(Agent)

The point is that a player to whom score is granted is QAgent (Player shooting the correct or wrong Trigger Device)
With PlayerScore : [player]int = map{}, How should I set QAgent and grant score to each player (who shoots) in AwardScore/PenaltyScore method?

If you have a good way, please tell me some advise.

Regards,

This is some basic coding, I think you have to learn about those, they might talk about it in the doc, or you can just look up for associative arrays on internet :+1:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.