How to transfer a value from one scene to another.

Hello all I am in the works of making a paintball game but am in need some help. I have an options scene where the user can change the number of points needed to win the game. Although I am stuck not knowing how to get it that value from that scene to the actual game scene where I would check to see if that value has been reached. This may have to be done via python scripting but was wondering if there is a way to do it without python and even if there isn’t how would I do this in python. I would like to know in python because I am at the point of where if I knew a little more about writing scripts I could do more with my game and the other game I am making for my other class.

Thanks for any help and if my blend file is needed just let me know and I can get it to you one way or another.

The quick and easy way to do this in Python is to assign a value to the logic module. Technically, the correct way to do this is to use the global dictionary (logic.globaDict). Here is an example. Change the particulars as you need.

Use a script to set the default value at startup. (Something like Initialize.py or whatever… trigger it with a Delay:0 sensor)

from bge import logic

logic.globalDict['points_needed'] = 5

Then update it when the options change. (“own[‘points_setting’]” would be a property on the object running the script.)

from bge import logic

own = logic.getCurrentController().owner

logic.globalDict['points_needed'] = own['points_setting']

Then check the value in game every time a point is scored. (I imagine you would have the player object run this script when a point is scored. “own[‘my_points’]” would be a property on the player object which triggers the script.)

from bge import logic

own = logic.getCurrentController().owner

if own['my_points'] >= logic.globalDict['points_needed']:
    <i># do something</i>

Edit:
BTW, the Python API is here (in case you didn’t know):
http://www.blender.org/documentation/blender_python_api_2_64_9/
Only use the modules in the “Game Engine” and “Standalone” sections.

Thank you I think I am on the right track. So this is what I have so far for checking to see if you win or the team wins.

import bge

controller = bge.logic.getCurrentController()
owner = controller.owner
if(bge.logic.globalDict[“score_limit”] <= owner[“playerteamtext”]):
#Add Overlay Scene for Team1wins
elif(bge.logic.globalDict[“score_limit”] <= owner[“enemyteamtext”]):
#Add Overlay Scene for Team2wins

but I am stuck not knowing how call the Scene Actuator and how to Add Overlay Scene with my Team2wins scene. Hopefully I can figure it out eventually but I think you will be able to help before I figure it out myself.

I just have this hooked up to a message sensor that i use to increase the enemy score and my teams score on the hud. That way each time someone scores it checks to see if they win? and if so will overlay the scene?

Thanks again for your help.

As long as the scene actuator is connected to the controller that calls the script:

controller = bge.logic.getCurrentController()
owner = controller.owner

if (bge.logic.globalDict["score_limit"] &lt;= owner["playerteamtext"]):
    team1_overlay = controller.actuators["actuator name goes here"]
    team1_overlay.scene = "Team1Wins"
    controller.activate(team1_overlay)
elif (bge.logic.globalDict["score_limit"] &lt;= owner["enemyteamtext"]):
    team2_overlay = controller.actuators["actuator name goes here"]
    team2_overlay.scene = "Team2Wins"
    controller.activate(team2_overlay)

Make sure your indentation is correct. Python is whitespace sensitive, so things that are at the same level (that is, in an if block or something) have to be indented identically.

You could also use a message, and then use a message sensor to trigger the overlay scene.

if (bge.logic.globalDict["score_limit"] &lt;= owner["playerteamtext"]):
    logic.sendMessage("Team 1 Wins")
elif (bge.logic.globalDict["score_limit"] &lt;= owner["enemyteamtext"]):
    logic.sendMessage("Team 2 Wins")

or you could use the state engine, but that’s a bit more complicated (though it is more resource friendly… something to learn later when you feel like it).

With most things in the BGE, there are at least 3 different ways to accomplish the same task. This is a good thing, because even if one method is broken, it is rarely true that something can’t be done.

Definitely getting closer although now my game is going non responsive and forcing me to close :frowning: So I shall explain what I did.

First I tried:

controller = bge.logic.getCurrentController()
owner = controller.owner
if (bge.logic.globalDict[“score_limit”] <= owner[“playerteamtext”]):
team1_overlay = controller.actuators[“Scene”]
team1_overlay.scene = “Team1wins”
controller.activate(team1_overlay)
elif (bge.logic.globalDict[“score_limit”] <= owner[“enemyteamtext”]):
team2_overlay = controller.actuators[“Scene”]
team2_overlay.scene = “Team2wins”
controller.activate(team2_overlay)

^
|
With the correct spacing. Sorry I am a noob and couldnt get the spaces to go where they should after the if and the elif cause i knew python is picky about spacing and indenting.

And this was connected to a message senser that looks for a message that is sent when someone is shot. Then I tried to do what you were saying or what I think you were saying. I created an actuator and made it a Scene and left the name as Scene. I changed it to add overlay scene and left the Scene: empty. I also tried adding one in there after it didn’t work which also didn’t work.

So then I changed the script to just be:

import bge

controller = bge.logic.getCurrentController()
owner = controller.owner
bge.logic.globalDict[“score_limit”] == owner[“playerteamtext”]

and connected it to the message sensor andthen connected this to a message sensor that sends a message to the same object with a subject of testwin and once that object received a message with the subject testwin I hooked it up to a Scene actuator that overlayed Team1wins.

That method unfortunately crashed as well although they were both crashing when I was hitting 10 which is what I was setting the score limit to be in the options.

I am sure I am just doing some silly mistake but not really sure what it is. I may just be doing it wrong in general but i feel like the reason is there I am just not executing it properly :slight_smile: