message body value in python

how do I get the value of a body of a message, or the value of all the messages that came in on that logic tic added up? this is the code I have so far.

# exp and leveling

import bge as g
cont = g.logic.getCurrentController()
player = cont.owner

levelup = cont.sensors["levelup"]
exp = cont.sensors["expget"]
level = player["level"]
exptnl = player["exptnl"]
expcur = player["exp"]


if exp.positive:
	expgot = int(exp.bodies[0])
else:
	expgot = 0

if levelup.positive:
	level2 = level * level
	level4 = level2 * level2
	level22 = (level - 1) * (level - 1)
	level44 = level22 * level22
	exptnl1 = int((level4 + 57 * level2) / 9)
	exptnl2 = int((level4 + 55 * level2 - 56) / 9)
	exptnl3 = int(1.0548 * (level44 + 55 * level22 - 56) / 9)
	
	if level = 1:
		player["exptnl"] = 15
	elif  level = 2:
		player["exptnl"] = 34
	elif  level = 3:
		player["exptnl"] = 57
	elif  level = 4:
		player["exptnl"] = 92
	elif  level = 5:
		player["exptnl"] = 135
	elif  level >= 6 and level < 32:
		player["exptnl"] = exptnl1
	elif  level >= 33 and level < 50:
		player["exptnl"] = exptnl2
	elif  level >= 51 and level < 200:
		player["exptnl"] = exptnl3

level = player["level"]
if  expgot + exp > exptnl:
	player["level"] += 1
	player["exp"] = int(expgot + exp - exptnl)
else:
	player["exp"] =+ expgot

exptnl?
expcur?
level22?

what should that mean?

you get the bodies of the message sensors with bodies as you already do. (the 2.49 API is a bit more organized)

double post!!
The answer is only 3 lines(!) deeper down!

@sevi it would have been a triple post because last night i forgot that i had less then 10 posts and i was like were is my thread at… then i posted it again and didn’t ignore the popup so i made 10 posts and reposted the thread i figured that whoever was going to approve it might notice that i had already reposted it after i got 10 posts but that didn’t happen because all they did was approve one and delete the other extra one.

Sorry for double posting I was just being impatient.

@monster
exptnl = experience points to the next level and expcur = current experience points

	level2 = level * level
	level4 = level2 * level2
	level22 = (level - 1) * (level - 1)
	level44 = level22 * level22
	exptnl1 = int((level4 + 57 * level2) / 9)
	exptnl2 = int((level4 + 55 * level2 - 56) / 9)
	exptnl3 = int(1.0548 * (level44 + 55 * level22 - 56) / 9)

that is just because I saw someone complain that you cannot just put^2 to square stuff or apply powers other then 2, but if there is some better way to apply powers to variables then please tell me.

and I think it looks better then this

	exptnl1 = int((level * level * level * level + 57 * level * level) / 9)
	exptnl2 = int((level * level * level * level + 55 * level * level - 56) / 9)
	exptnl3 = int(1.0548 * ((level - 1) * (level - 1) * (level - 1) * (level - 1) + 55 * (level - 1) * (level - 1) - 56) / 9)

and the reason I am using this for the exp curve is because I am making a 3d version of a 2d game. I will be asking for help with modeling after I get a decent amount of it done.

Anyways thanks it works for a single message now. I just need to make it get the value of all the bodies added up. maybe use

# exp and leveling

import bge as g
cont = g.logic.getCurrentController()
player = cont.owner

levelup = cont.sensors["levelup"]
exp = cont.sensors["expget"]
level = player["level"]
exptnl = player["exptnl"]
expcur = player["exp"]
print (exp.bodies)

if exp.positive:
	expgot = int(exp.bodies[0])
else:
	expgot = 0

if levelup.positive:
	level2 = level * level
	level4 = level2 * level2
	level22 = (level - 1) * (level - 1)
	level44 = level22 * level22
	exptnl1 = int((level4 + 57 * level2) / 9)
	exptnl2 = int((level4 + 55 * level2 - 56) / 9)
	exptnl3 = int(1.0548 * (level44 + 55 * level22 - 56) / 9)
	
	if level == 1:
		player["exptnl"] = 15
	elif  level == 2:
		player["exptnl"] = 34
	elif  level == 3:
		player["exptnl"] = 57
	elif  level == 4:
		player["exptnl"] = 92
	elif  level == 5:
		player["exptnl"] = 135
	elif  level >= 6 and level < 32:
		player["exptnl"] = exptnl1
	elif  level >= 33 and level < 50:
		player["exptnl"] = exptnl2
	elif  level >= 51 and level < 200:
		player["exptnl"] = exptnl3

level = player["level"]

if  (expgot + player["exp"]) >= exptnl:
	player["level"] += 1
	player["exp"] = int(expgot + player["exp"] - exptnl)
else:
	player["exp"] += expgot

and if anyone can see any way to improve this to make it run better tell me.

use **2 for squares :slight_smile:


# exp and leveling

import bge as g
cont = g.logic.getCurrentController()
player = cont.owner

levelup = cont.sensors["levelup"]
exp = cont.sensors["expget"]
level = player["level"]
exptnl = player["exptnl"]
expcur = player["exp"]
print (exp.bodies)

if exp.positive:
	expgot = int(exp.bodies[0])
else:
	expgot = 0

if levelup.positive:
	level2 = level**2
	level4 = level2**2
	level22 = (level - 1) **2
	level44 = level22 **2
	exptnl1 = int((level4 + 57 * level2) / 9)
	exptnl2 = int((level4 + 55 * level2 - 56) / 9)
	exptnl3 = int(1.0548 * (level44 + 55 * level22 - 56) / 9)
	
	if level == 1:
		player["exptnl"] = 15
	elif  level == 2:
		player["exptnl"] = 34
	elif  level == 3:
		player["exptnl"] = 57
	elif  level == 4:
		player["exptnl"] = 92
	elif  level == 5:
		player["exptnl"] = 135
	elif  level >= 6 and level < 32:
		player["exptnl"] = exptnl1
	elif  level >= 33 and level < 50:
		player["exptnl"] = exptnl2
	elif  level >= 51 and level < 200:
		player["exptnl"] = exptnl3

level = player["level"]

if  (expgot + player["exp"]) >= exptnl:
	player["level"] += 1
	player["exp"] = int(expgot + player["exp"] - exptnl)
else:
	player["exp"] += expgot

In that case select a naming convention and name your variables like that.
e.g. currentExperiencePoints or current_experience_points

You will thank yourself when you try to understand this code next month ;).

Additionaly benefit:
You get much better help if a reader can understand what the code should mean.

Ok well I figured out how to do it…

@monster sorry I am to lazy to change the code now. to make it easy to read. I know what everything means I am just throwing together the first part of the game to get as much done as fast as I can, because I have not done any coding before just used logic bricks.

I plan on getting everything that I need to work working. then reworking it all into module format and optimizing it. I will be combining a lot of the individual scripts that I end up with too I just want to get a Prof of concept, before I start on the details…

and after I get the game to a playable state then the real work begins (this is when i would start asking for help from modelers)… there are thousands of different equipments and thousands of different monsters to make and like a few hundred skills to add… as well as over 50 boss type monsters.

# exp and leveling

import bge as g
cont = g.logic.getCurrentController()
player = cont.owner

exp = cont.sensors["expget"]
spawn = cont.actuators["Spawn2"]

level = player["level"]
exptnl = player["exptnl"]
expcur = player["exp"]
numberofmsgs = int(exp.frameMessageCount)

expgot = 0

while numberofmsgs >= 1:
	print (numberofmsgs)
	numberofmsgs = numberofmsgs - 1
	print (expgot)
	expgot += int(exp.bodies[(numberofmsgs)])
	print (numberofmsgs)
	print (expgot)

while (expgot + expcur) >= exptnl:
	player["level"] += 1
	level += 1
	expgot = expgot - exptnl
	spawn.instantAddObject()
	
	if level == 1:
		player["exptnl"] = 15
		exptnl = 15
	elif  level == 2:
		player["exptnl"] = 34
		exptnl = 34
	elif  level == 3:
		player["exptnl"] = 57
		exptnl = 57
	elif  level == 4:
		player["exptnl"] = 92
		exptnl = 92
	elif  level == 5:
		player["exptnl"] = 135
		exptnl = 135
	elif  level >= 6 and level < 32:
		player["exptnl"] = int((level**4 + 57 * level**2) / 9)
		exptnl = int((level**4 + 57 * level**2) / 9)
	elif  level >= 33 and level < 50:
		player["exptnl"] = int((level**4 + 55 * level**2 - 56) / 9)
		exptnl = int((level**4 + 55 * level**2 - 56) / 9)
	elif  level >= 51 and level < 200:
		player["exptnl"] = int(1.0548 * ((level-1)**4 + 55 * (level-1)**2 - 56) / 9)
		exptnl = int(1.0548 * ((level-1)**4 + 55 * (level-1)**2 - 56) / 9)

player["exp"] = expgot + expcur

oh i forgot this is a script that when the exp msg is sent to the player adds the exp. on monster death have them send a message with their exp property as the body if anyone else is making a game with exp and levels then this might be useful to you and you can do whatever you want with my messy code.