# I am trying to learn about player and agent and i have trouble with my code

**URL:** <https://forums.unrealengine.com/t/i-am-trying-to-learn-about-player-and-agent-and-i-have-trouble-with-my-code/1684388>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [February 12, 2024, 6:50pm UTC](https://forums.unrealengine.com/t/i-am-trying-to-learn-about-player-and-agent-and-i-have-trouble-with-my-code/1684388 "2024-02-12T18:50:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valthekiller2006](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/valthekiller2006/32/897096_2.png) [@Valthekiller2006](https://forums.unrealengine.com/u/Valthekiller2006)\
**Post date:** [February 12, 2024, 6:50pm UTC](https://forums.unrealengine.com/t/i-am-trying-to-learn-about-player-and-agent-and-i-have-trouble-with-my-code/1684388/1 "2024-02-12T18:50:54Z")

</div>

> So i am trying to make a device that the less often you shoot the more you deal damage.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/b/3/eb39fa5970bcada99f24b0cd23638f7f9a35ca29.png)

> i’m a beginner at Verse and the problem is that i can’t find out what to put inside of the parentheses of TimeMultiplicator in the onBegin function

---

<div class="post-metadata">

**Author:** ![The3v0luti0n](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/the3v0luti0n/32/897083_2.png) [@The3v0luti0n](https://forums.unrealengine.com/u/The3v0luti0n)\
**Post date:** [February 12, 2024, 7:03pm UTC](https://forums.unrealengine.com/t/i-am-trying-to-learn-about-player-and-agent-and-i-have-trouble-with-my-code/1684388/2 "2024-02-12T19:03:49Z")

</div>

When subscribing to events, you do not use any parentheses in the call.

```auto
OnBegin<override>()<suspends> : void = 
        InputFiring.PressedEvent.Subscribe(TimeMultiplicator)

```

---

<div class="post-metadata">

**Author:** ![Valthekiller2006](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/valthekiller2006/32/897096_2.png) [@Valthekiller2006](https://forums.unrealengine.com/u/Valthekiller2006)\
**Post date:** [February 12, 2024, 7:06pm UTC](https://forums.unrealengine.com/t/i-am-trying-to-learn-about-player-and-agent-and-i-have-trouble-with-my-code/1684388/3 "2024-02-12T19:06:42Z")

</div>

yeah but when i remove the parentheses there is an other error

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/b/e/dbe39eb7389519eab0b71215dc29f0c36a19c51f.png)

---

<div class="post-metadata">

**Author:** ![The3v0luti0n](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/the3v0luti0n/32/897083_2.png) [@The3v0luti0n](https://forums.unrealengine.com/u/The3v0luti0n)\
**Post date:** [February 12, 2024, 7:09pm UTC](https://forums.unrealengine.com/t/i-am-trying-to-learn-about-player-and-agent-and-i-have-trouble-with-my-code/1684388/4 "2024-02-12T19:09:00Z")

</div>

That is because you have defined the TimeMultiplicator() function as a `<suspends>`. In general, events don’t use that.

Replace with:

```auto
TimeMultiplicator(Agent : agent) : void=
            ...

```

---

<div class="post-metadata">

**Author:** ![Valthekiller2006](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/valthekiller2006/32/897096_2.png) [@Valthekiller2006](https://forums.unrealengine.com/u/Valthekiller2006)\
**Post date:** [February 12, 2024, 7:11pm UTC](https://forums.unrealengine.com/t/i-am-trying-to-learn-about-player-and-agent-and-i-have-trouble-with-my-code/1684388/5 "2024-02-12T19:11:07Z")

</div>

but then i can’t use the sleep() function for my timer

---

<div class="post-metadata">

**Author:** ![The3v0luti0n](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/the3v0luti0n/32/897083_2.png) [@The3v0luti0n](https://forums.unrealengine.com/u/The3v0luti0n)\
**Post date:** [February 12, 2024, 7:38pm UTC](https://forums.unrealengine.com/t/i-am-trying-to-learn-about-player-and-agent-and-i-have-trouble-with-my-code/1684388/6 "2024-02-12T19:38:31Z")

</div>

Alright, here is a suggestion on how you could rework this a bit.

Instead of calling the TimeMultiplicator() whenever the InputFired event goes off, instead we will have the TimeMultiplicator() running independently all the time. To do this, we use the `Spawn` functionality. This allows the TimeMultiplicator() function to operate on it’s own, without holding up the rest of the device.

The next thing would be to modify the TimeMultiplicator() so that it goes forever once started, but using Sleep() to make it run only every so often. The idea is that this function could look to see if the player has shot, and if they have, call the DecreaseMultiplier(). Otherwise, if they haven’t, call the IncreaseMultiplier().

You would then need another variable like “PlayerShot” to determine if you need to increase/decrease. This is set by the pressed event of the InputFiring, and reset inside of the loop for the TimeMultiplicator().

Here is some pseudocode of what I mean

```auto
var PlayerShot : logic = false

OnBegin<override>()<suspends> : void = 
        spawn:
                TimeMultiplicator()

        InputFiring.PressedEvent.Subscribe(OnPressedEvent)

TimeMultiplicator()<suspends> : void=
        loop:
              if (PlayerShot = true):
                  IncreaseMultiplier()
                  PlayerShot = false
              else if (PlayerShot = false):
                  DecreaseMultiplier()
              else:
                  break
              Sleep(0.1)

OnPressedEvent(Agent: ?agent):void=
        set PlayerShot = true

```

However, this currently will not work with multiple players. To do so, you would need to use a Map data structure that uses the Player as a key, and the value of PlayerShot. Then, inside of your TimeMultiplicator(), just loop through all the active players, and increase/decrease depending on the value of their corresponding PlayerShot.

---

<div class="post-metadata">

**Author:** ![Valthekiller2006](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/valthekiller2006/32/897096_2.png) [@Valthekiller2006](https://forums.unrealengine.com/u/Valthekiller2006)\
**Post date:** [February 12, 2024, 7:48pm UTC](https://forums.unrealengine.com/t/i-am-trying-to-learn-about-player-and-agent-and-i-have-trouble-with-my-code/1684388/7 "2024-02-12T19:48:18Z")

</div>

Thank you so much

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [March 13, 2024, 7:49pm UTC](https://forums.unrealengine.com/t/i-am-trying-to-learn-about-player-and-agent-and-i-have-trouble-with-my-code/1684388/8 "2024-03-13T19:49:05Z")

</div>

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