can't figure out how to extract variables from a dictionary or if any other solution is possible

Hello world! I am making a VERY troublesome code, which for unrelated reasons to this question requires me to do EVERYTHING in a function, so instead of

while result == None:
    #all of the game process happens here

I have to use this:

def mainfunction(some variables):
    #all of the game process happens here

while result == None:
    mainfunction()

But that didn't work, because mainfunction() changes some of the variables that IT USES, and every single loop it would change different variables, so I can't just put the variables in return.

So instead I created a dictionary, which will be returned from mainfunction() at the end of every loop, in which all of the variables that get changed get stored

Where the keys are the names of the variables and the values are the things that the variables store. So far so good! I have returned the dictionary from the mainfunction()! But... what now? How on EARTH am I supposed to revert them back to variables? Or even if that's impossible, can I use dictionaries in some other way to do this? Or is there ANY other way to do this?