libload problem

I am trying to use libload but it is not working.It is sdfgeoff code.

import bge
path_to_other_blend = bge.logic.expandPath('//Relative/password.blend')
bge.logic.LibLoad(Desktop/password, 'Scene')

Is that the exact code you have used? If so you need to adjust the file paths.
The function “expandPath” takes the current working directory (//) and adds a relative path to a subdirectory or file inside your game folder (Relative/password.blend).
In line 3 you try to access your desktop folder but the bge cant find it since it is located elsewhere (windows shows it just as a shortcut. the real desktop folder is usually located under “C:\Users\myname\Desktop” but I would strongly recommend putting all files inside your project directory.
To open the “password.blend” it should look like the following (if it is in a subfolder of your project directory called “Relative”)

c:\projects\currentproject\Relative\password.blend

path_to_other_blend = bge.logic.expandPath('//Relative/password.blend')
bge.logic.LibLoad(path_to_other_blend, 'Scene')

Hint:
You can show the error output in a console window which you can open in “Window” menue “Toggle system console”

Is this correct?

import bge
path_to_other_blend = bge.logic.expandPath('//Relative/password.blend')
bge.logic.LibLoad(C:\Users\barbara scott\Desktop
ut and bolt\password, 'Scene')

how about some string marks? -> ’ or "

Why define a path to the file then manually enter it? Wendingo wrote the correct example.

So relative is a directory?


import bge
path_to_other_blend = bge.logic.expandPath('//Relative/password.blend')
bge.logic.LibLoad(path_to_other_blend, 'Scene')

Wendingo provided the above,
path_to_other_blend is a string variable with the path to the blend file, where relative is a directory.

Okay, I will try it.

import bge
path_to_other_blend = bge.logic.expandPath('//Desktop/nut and bolt/password.blend')
bge.logic.LibLoad(path_to_other_blend, 'Scene')

How would i write the file path to the blend file on windows 8?Because it is not working?

The second line is defining a python variable, storing your path in this thing called ‘path_to_other_blend’. Try inserting the line “print(path_to_other_blend)” between lines two and three. Have a look in the systemm console to see what happens.
The third line takes uses the variable (remember, it’s storing the path) and uses bge to load it.

Possible problems:

  • Incorrect path. The path is relative to the blend running the script (usually). Printing the path as described above will allow you to check this.
  • Syntax error. If you leave out a bracket or quotation mark, python wont know what to do with it
  • I goofed. It is possible I made an error when posting that code snippet. I’m pretty sure I didn’t though!

Just a reminder about bge code: run it from a script via logic bricks, not the run code button.

Here’s a demo blend(s):

Your blend is libnew.This is about using libload not libnew.Put in print (path_to_other_blend) with or without quotation marks?

Do you understand what expandPath does? It makes a relative path absolute to the current blend file. It seems odd you’d have a folder called Desktop, unless you’re running from your User directory?

The folder is on my desktop.

Could you give me a simple blend example of libload and libfree?

Oh sorry, the libload demo is here:

They all exist in my workroom, which can be found in my signature

I don’t have a libfree demo, but you just feed it the blend name.

Thankyou for the blends and information sdfgeoff.I see what libload could be useful for.It could be useful if you want to load another level while keeping the player character where he is.