Jump to content

[SOLVED] Error can't open scripts/class. Win32 OpenFileName()


Road Kill Kenny
 Share

Recommended Posts

Hi all,

 

A video can explain this issue much better so see below...... This issue is just very very strange and I was wondering if anyone has come across it before and if there is a solution.

 

Enjoy the easter eggs.

 

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

It would be nice to see that LUA-script and that error message. Source code must say much more than video in this case.

 

I think something wrong with paths.

 

Try to replace relative path to script "scripts/class" with abstract one "abstract::class".

 

The error is: "can't open scripts/class"

 

The paths should be irrelevant as it works In all other instances as shown in the video. However, I did try abstract::class instead to no avail. If the path is the problem then It doesn't make sense that it will work one second and not the next.... with the exact same LoadModel() function call.

 

There is no point showing you the script itself because there is nothing wrong with it. The exact same script works in the editor and in the actual game and strangely when I add objects in the editor but not when I load a level with the editor.....

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Ok so here is the source code that matters. I'm rather certain it is all correct but I'll show you anyway:

 

LE::TFramework fw = CreateFramework();
if(!fw)
MessageBoxA(NULL, "Error 03: Failed to Create Framework", "Error LE-03", MB_OK);


LE::SetAppTitle("Level Editor");
LE::RegisterAbstractPath(K_Win::GetAppPath().c_str());
//K_Win::GetAppPath() returns the path to the folder of the .exe application file.

//Lua Setup
LE::BP lua = LE::GetLuaState();
LE::lua_pushobject(lua, fw);
LE::lua_setglobal(lua, "fw");
LE::lua_pop(lua, 1);

 

Loading of the model in both instances. Note that I don't use abstract path in the C++ code at all anymore. So these arguments that may look foreign are simply absolute paths.

//This is how it is called when loading a scene
gateModel = LE::LoadModel((lvlDat->gameDir + lvlDat->csGatePath.at(CS_ID)).c_str());


//And this is how it is called when simply adding to the scene
gateModel = LE::LoadModel((lvlDat->gameDir + lvlDat->csGatePath.at(CS_ID)).c_str());

 

Yes they are indeed exactly the same and the arguments calculate to be the exact same path as well granted that CS_ID is the same. These are called within a Gate class in the constructors. It has a constructor for loading from database (DDD) and a non DDD constructor for when you want to add one to the scene with default settings. They only differ slightly and in no way do they effect this LoadModel() function call.

 

Both the game and the editor work straight out of the same folders too.. so I really have ran out of things that I can think of even trying to do that will solve this.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Yes I have, no difference.... It's still a mystery as to why it works when adding to scene and not when loading file.

 

I think this is going to come down to a workaround rather than a solution. Just thought I'd check in see if anybody has ever experienced this.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

I get this error message frequently 'can't open scripts/class' in some of my builds, the bad news is it tends to be intermittent and I have never found a solution to it yet, not that I have been using Lua for long.

 

My Leadwerks to EKI One executable always displays this error and my current Neutrino Engine Editor sometimes throws this error and other times doesn't; and that's on consecutive runs! In both cases the scripts directory is in the root of the application. I would be very interested to find the reason behind this too.

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

I have to imagine it's something to do with the setup you guys have. I have never had this error other than not having the scripts folder in the same dir as the running exe. I'm pretty sure I also never use RegisterAbstractPath() function as it must default to the exe dir and subdirs if you don't call it.

Link to comment
Share on other sites

Is the current working directory correct? I got that error because I was pushing all of my binaries to a separate folder. I made a bat file to launch the game ./bin/game.exe

 

Lua uses a special variable to see where the loading paths are.

 

http://lua-users.org/wiki/PackagePath

 

That could give you insight.

Thanks ChrisMAN, I'll take a look at that.

 

Regarding my executables, yes I do the same, I build to debug and release sub directories but this occurs when the executable has been copied to the root directory of the application which contains the scripts directory! Clearly something is causing this, I've just not isolated it yet!

 

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

Abstract paths do not work with the lua 'require', hence the fact you have to have the 'Scripts' folder located within your project to access the class script. The only thing that I could suggest is to have the Scripts folder be located in your editor's executable folder and have a reference to require it in 'Start' folder. I have never gotten this error either unless my project folder was missing the 'Scripts' folder.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

This is why it is wierd guys... I've done this plenty of times before scripts folder is in the right place. Abstract path is not the problem... Even if I remove that line it still does the same thing. The binaries are ain the same folder as scripts folder.. no separate folders.

 

The paths are correct.... If they weren't it wouldn't work ever.... not just in this one instance when loading a scene. That is what makes this problem strange.

 

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Ok so here is the source code that matters.

I asked about LUA-script which invokes "scripts/class". How does it do? With require command? It must be somewhere in your attached to model "gate.lua" file I suppose.

 

I can assume only that this two cases use LUA environment with different states. And search path may be changed. You can check search path in than lua script:


AppLog(package.path)

 

Add this line right before "scripts/class" invoking. And watch the LOG-file. For both cases.

  • Upvote 1
Link to comment
Share on other sites

I'm pretty sure in my case I don't have multiple Lua states but that code will be useful to see where it thinks it's looking for the scripts when these errors occur.

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

I asked about LUA-script which invokes "scripts/class". How does it do? With require command? It must be somewhere in your attached to model "gate.lua" file I suppose.

 

I can assume only that this two cases use LUA environment with different states. And search path may be changed. You can check search path in than lua script:


AppLog(package.path)

 

Add this line right before "scripts/class" invoking. And watch the LOG-file. For both cases.

 

Will try this when I get home\

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Tried the AppLog(pagage.path) thing and it was identical in both instances.

 

Abstract paths do not work with the lua 'require', hence the fact you have to have the 'Scripts' folder located within your project to access the class script. The only thing that I could suggest is to have the Scripts folder be located in your editor's executable folder and have a reference to require it in 'Start' folder. I have never gotten this error either unless my project folder was missing the 'Scripts' folder.

 

Thanks, for this work around mack.... I put the class script in the start folder and because it loads it at start up it works... .It still throws the error when loading the scenr but it should do the trick for now.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Abstract paths do not work with the lua 'require'

It works very well for me. But I write my game entirely in LUA.


require("abstract::core")

require("abstract::filesystem")

require("abstract::string")

require("abstract::vector")

require("abstract::properties")

  • Upvote 1
Link to comment
Share on other sites

It works very well for me. But I write my game entirely in LUA.

 

Then this has changed without notice because it had not in the past and was repeatedly stated as such from the developer. And from what I just checked with my older versions of LE, this did not work until LE2.42. This would have been good information to know. But this is good news, so thanks for the information, Daimour!

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Could that "Open file..." window change current working directory?

 

Try to load a scene with hardcoded path without opening dialog.

 

It is impossible for this to change the path for LUA... All the open file thing is is a function that uses the Win32 API to get an open file dialog box which returns a std::string

 

static std::string K_Win::FileOpen(){

  OPENFILENAME ofn;
  char fileName[MAX_PATH] = "";
  ZeroMemory(&ofn, sizeof(ofn));
  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.hwndOwner = NULL;
  ofn.lpstrFilter = "SQLite3 Files (*.*)\0*.*\0";
  ofn.lpstrFile = fileName;
  ofn.nMaxFile = MAX_PATH;
  ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  ofn.lpstrDefExt = "";
  std::string fileNameStr;
  if(GetOpenFileName(&ofn))
      fileNameStr = fileName;

return fileNameStr;
}

 

And the it is simply called like this

lvlDat->SetLoadFile(K_Win::FileOpen());

 

The lvlDat is a LevelData* class and it has no ability to change the abstract path or any other path. SetLoadFile simply changes a std::string variable in the LevelData class that is then used to open an SQLite Database and query it.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Look here: http://msdn.microsof...7(v=vs.85).aspx

 

Pre-last comment.

 

Hmm very interesting.... and rather annoying that it changes the directory. Not sure why it does, I can't see any value in changing the working directory considering the GetOpenFileName() function returns an absolute path and not a local file name.

 

Thanks for the info. I should be able to solve it based on that info

 

If I use SetCurrentDirectory() immediately after GetOpenFileName() to change the directory back to the default directory then it should work.

http://msdn.microsof...0(v=vs.85).aspx

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

When the user selects at least one file and clicks the OK button, the process' current working directory is changed to the directory contain the file(s) being opened.

Many thanks Daimour, this definietely explains why it's happening in one of the the cases I was experiencing and quite possibly in both. It only happens in apps that have file open dialogs so it looks highly likely!

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

Yes thanks a lot Daimour. It works perfectly now. Never would have thaught the win32 Api function call had anything to do with it lol.

 

Here's the new code for that function, works the charm biggrin.png

 

static std::string K_Win::FileOpen(){

  OPENFILENAME ofn;
  char fileName[MAX_PATH] = "";
  ZeroMemory(&ofn, sizeof(ofn));
  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.hwndOwner = NULL;
  ofn.lpstrFilter = "SQLite3 Files (*.*)\0*.*\0";
  ofn.lpstrFile = fileName;
  ofn.nMaxFile = MAX_PATH;
  ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  ofn.lpstrDefExt = "";
  std::string fileNameStr;

  char curDir[MAX_PATH];
  GetCurrentDirectory(MAX_PATH, curDir);

  if(GetOpenFileName(&ofn))
     fileNameStr = fileName;

  SetCurrentDirectory(curDir);

  return fileNameStr;
}

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...