Cannot Cancel A Subscription based on tutorial

Hi everyone. 2 Days ago I started learning verse and I am working through the Epic tutorials. I am following this tutorial Coding Device Interactions The problem is that even though I copied and pasted the code exactly nothing gets added to my array and I can run the event multiple times. Is this happening to you as well or am I missing something , maybe a setting somewhere else ?

Thanks in advance for your time and help.

Best regards.

had a qiuck look but i dont see any array in those code blocks

that tutorial shows you the different methods on subscribing to events

when you subscribe to an event you are telling the code to listen for the event signal you have subscribed to

when the code detects the signal it calls the function contained within the brackets and passes the agent

eg

MyButtonDevice.InteractedWithEvent.Subscribe(OnButtonInteractedWith)

would call the OnButtonInteractedWith function

you can use print statements to do abit of logging on screen whilst you test your code that may help you debug

post your code and any errors you get with a brief description what you are trying to do

Thanks for your help I will try that and see what happens

ButtonSubscription := Button.InteractedWithEvent.Subscribe(OnButtonInteractedWith)
# Add the cancelable result to a spot in the Subscriptions array.
CPrint(“Hello”)
if(set Subscriptions[0] = ButtonSubscription):
CPrint(“Subscribed to the Button’s InteractedWithEvent and set the subscription in Subscriptions!”)
else:
Print(“Sub failed”)

If you add an else statement, you will see the array is failing to initialize. The code does compile without error but adding or accessing values from an array is a failable expression and it is definitely failing. If I can figure out why, I will update. One solution is to just get rid of the array for now, so you can see how the button event and the cancel sub function works. The array is not required for that functionality.

Watch this video:
Verse Code Exampe

2 Likes

Thank you man

Thanks for the link I will watch it

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