So i am trying to make a device that the less often you shoot the more you deal damage.
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
So i am trying to make a device that the less often you shoot the more you deal damage.
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
When subscribing to events, you do not use any parentheses in the call.
OnBegin<override>()<suspends> : void =
InputFiring.PressedEvent.Subscribe(TimeMultiplicator)
That is because you have defined the TimeMultiplicator() function as a <suspends>
. In general, events don’t use that.
Replace with:
TimeMultiplicator(Agent : agent) : void=
...
but then i can’t use the sleep() function for my timer
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
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.
Thank you so much
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.