# Issues with calling Lua functions from C++.

This topic is 2805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Nevermind, the code itself seems to work fine. I ended up naming two functions the same thing, I had a legitimate error where one of the functions WAS missing from the script files, only I'd forgotten I'd named it the same thing as the functions I was dealing with here. Ergo, I was getting perfectly reasonable error messages about some OTHER function, but thought it was about THIS function because they had the same name.

Lesson: Don't program anything for at least a week after daylight savings time ends.

----

Basically, every object in my engine is scripted using Lua. This seems to be working fine. I'm now trying to add level-wide Lua scripts that get called at the beginning of every turn and whenever the player enters the level for the first time. This is not working so well.

The level script function calling code is in the nopaste link above. What it should be doing is loading a filename (based off the name assigned to the level. It's assumed that a level's name, directory, and script all have the same basic name), either in the form of an uncompiled or compiled lua file, generates a call string, sends the function call string to lua, and returns.

In terms of outward behaviors, everything works. The functions I try to call get called, they do what they're told, and everything LOOKS fine.

However, I get an stderr.txt file as output with a bunch of stuff like:

actors/wall.lua: [string "LevelEntered"]:1: attempt to call global LevelEntered' (a nil value)
actors/wall.lua: [string "LevelEntered"]:1: attempt to call global LevelEntered' (a nil value)
actors/creatures/dvorak.lua: [string "LevelEntered"]:1: attempt to call global LevelEntered' (a nil value)
actors/player.lua: [string "LevelEntered"]:1: attempt to call global LevelEntered' (a nil value)

Which are error message generated by the actual game object scripts when something tries to call a non-existent function in them. In this particular case, LevelEntered is a function I previously called in one of the level scripts.

It sort of looks like LevelEntered is getting stuck on the call stack somehow although I'm not entirely sure this is the case and I'm not entirely sure why this is happening.

Also it seems like the issue resolves itself after the first turn following the level script being run since each game object only generates one of the error messages above once, instead of once per turn.

[Edited by - MeshGearFox on November 9, 2010 11:29:53 PM]

1. 1
Rutin
21
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 26
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001781
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!