Can't pass ?agent as an argument due to "no rollback" and "decides effect"

I’m trying to make a function that prepares the player for a round, granting items, and related actions. This line simply calls the GrantItem() function inside an ItemGranter device.

The problem is, I can’t really pass an ?agent as parameter (the person who should receive the item), since I always get a different problem.

Example codes:

Can’t do this, since ?agent is a “nullable” data and can generate errors case it’s “null”

Then I try to add an IF statement in order to make it “safe”, and get the no_rollback effect…

What is the right way of doing this? I keep having problems with ?agents because of these 2 rules, can someone please help? Thanks in advance!

You’re basically trying to call a no_rollback function GrantItem() at the same time as a decides in the same line which is not possible. Instead, do the if check for the optional first then pass that as the argument

if ( Agent := Target?):
    ItemGranter.GrantItem(Agent)
1 Like

Thanks for the Reply, 1-UP!
Just to see if I understood correctly:

" if ( Agent := Target?): "
Means we are trying to declare a local variable of the same type as Target (?agent), and if the action is successful, then we call the “GrantItem()” function?

I’m kinda lost about the type of “Agent”, is it an “agent” and not “?agent” anymore? If so, why exactly?

Thanks in advance!!

1 Like
if(MyTarget := Target):
    ItemGranter.GrantItem(MyTarget)

so as i understand it and i could be wrong

Agent is just a variable you create to store an agent

the difference between agent and ?agent is the agent definatly exists
the ?agent possibly dont exist

Yup, that’s essentially it.
(Agent := Target? )
is basically saying try to get an agent from the Target which is an optional ?agent. Optionals can ether be false or hold a value, in this case an agent.

That’s why you try to assign it inside an if statement, because if Target is false, then the entire expression will evaluate to false which means the GrantItem() won’t run.

1 Like

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