This is sooo confusing! "Decides function"

This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context. The ‘decides’ effect indicates that the invocation calls a function that might fail, and so must occur in a failure context that will handle the failure. Some examples of failure contexts are the condition clause of an ‘if’, the left operand of ‘or’, or the clause of the ‘logic’ macro.

i have 4 chairs and i want to call a function as soon as all of those Chairs are populated, i subscribed to the Seated event of each chair and linked it to a function that increases a playercount int and Calls another function which “starts the game” as soon as the playercount hits 4 (1 for testing purposes). Now as soon as the game starts i wanna draw a random word. This is where everything gets confusing.

chooseword(): void =

    Print("choosing word")    
    rndmnumber := GetRandomInt(0, Wordlist.Length)
    Print(Wordlist[rndmnumber])

Choosing my random number as the number in the wordlist array automatically turns this into a decides function and it gives me errors if its not a decides function.

Now if i wanna call the chooseword function:

IncreasePlayerCount(Agent:agent):void =
set Playercount += 1
Print(ToString(Playercount))
if(Playercount = 1):

    chooseword[] 

This gives me the error: “This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context. The ‘decides’ effect indicates that the invocation calls a function that might fail, and so must occur in a failure context that will handle the failure. Some examples of failure contexts are the condition clause of an ‘if’, the left operand of ‘or’, or the clause of the ‘logic’ macro.”

How can i call a decides Function inside a non decides function???
I had this problem with a suspends function before and managed to get away by using “spawn:” but how does it work with decides functions??

Anything that requires a decides context just means do wrap it in an if statement!

Checking a value in an Array always needs to take place in a decides context, other functions as long as they have the <transact> specifier, can be in there too.

if:
    rndmnumber := GetRandomInt(0, Wordlist.Length) #not decides but can be in here
    RandomWord := Wordlist[rndmnumber]
then:
   Print(RandomWord)

if:
   chooseword[]
then:
2 Likes

Im sorry but this didnt really help. Ive moved past the original code tho by switching some stuff up but now im facing the same problem! Its always this gosh darn decides function when doing something random.

I wanna pick a random player at the start, sounds simple enough but im having immense trouble.

RandomPlayerClass : class_and_team_selector_device = class_and_team_selector_device{}



# Runs when the device is started in a running game
OnBegin<override>()<suspends> :void =
   if{ Decide[] } 

    
Decide()<decides>: void =
    AllPlayers := GetPlayspace().GetPlayers()
    Randomplayernumber := GetRandomInt(0, AllPlayers.Length-1)
    RandomPlayer := AllPlayers[Randomplayernumber]
    RandomPlayerClass.ChangeClass(RandomPlayer)    

Same Problem, the line where i call the decide function has following error “This invocation calls a function that has the ‘no_rollback’ effect, which is not allowed by its context.” meaning from what i know that it needs . But as soon as i add transacts this line:

RandomPlayerClass.ChangeClass(RandomPlayer)

Gets the same error “This invocation calls a function that has the ‘no_rollback’ effect, which is not allowed by its context.” I need both transacts and defines but I cant have transacts due to this line and if i dont have transacts i cant call the function. I dont know, i may just not get it but it seems contradicting to me, either way it confuses me and i neeed help.

Basically anything that uses square brackets [ ] should go into an if statement. I don’t think you need the decides specifier on the decide function, you can just run Decide() normally in your onbegin but you’ll need to move RandomPlayer := AllPlayers[Randomplayernumber] into an if statement because that’s the line using square brackets (because it is trying to access an array it is decides and square brackets because it is possible that there is nothing to return) . Using the if: then: syntax instead of if{} also makes things more readable

1 Like

The ChangeClass function has a no rollback specifier so you can’t use it in an if block. You could put it in a then block. You don’t have to give that function a decides specifier.

Thank you SO MUCH!!!

1 Like