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”
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)
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?
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.