Defining string or some kind like that

Hi everyone,
im having trouble with these lines
path = path + “_” + ID
bge.logic.LibLoad((url + path),‘Scene’,verbose=True)

in this following script. Could anyone fix it for me? It keeps saying "could not open blendfile “D:\BlenderMusic\other\path3”. But i want this path_3 to be this “B2ST.blend”


import bge


cont = bge.logic.getCurrentController()
own = cont.owner


scene=bge.logic.getCurrentScene()


url = bge.logic.expandPath("//other\\")


ID = str(own["mapnr"])


path_1 = "Simple.blend"
path_2 = "MightySoya.blend"
path_3 = "B2ST.blend"
path_4 = "Leehyori.blend"
path_5 = "BESTie.blend"
path_6 = "Spacestage.blend"
path_7 = "KStreet.blend"
path_8 = "Skystage.blend"
path_9 = "Arcade.blend"
path_10 = "Office.blend"




change = cont.sensors["mapchange"]
free = cont.sensors["mapfree"]
#ch_m = cont.sensors["ch_map"]




if change.positive:
    path = path + "_" + ID
    bge.logic.LibLoad((url + path),'Scene',verbose=True)

can someone help me please?

The logic of what you wrote is sound, unfortunately it is not the same of the python grammar.

You can replace

path = path + “_” + ID

with

path = eval(“path_” + ID)

That translates to “path is the value of the variable, available in the current scope, named “path_” + some number”.

A less tricky solution would be to use a dictionary:


idToPath = {
"1":path_1,
"2":path_2,
"3":path_3,
"4":path_4,
"5":path_5,
"6":path_6,
"7":path_7,
"8":path_8,
"9":path_9,
"10":path_10
}

Then you write:

path = idToPath.get(ID)

In the dictionary you can replace the path_x with the corresponding string values.

thanks alot pgi