• Content count

  • Joined

  • Last visited

Community Reputation

139 Neutral

About satsujin

  • Rank
  1. Hi folks, I have been trying to move my xna input checks into Lua. It has worked for the most part but strangely while the speed is fine in C# when I move the script to Lua, the keyboard input seems to have a bug in it where it lags before responding. If I just press and release the Space key nothing comes in my output windows but it works if i hold it down for about 2-3 seconds and release it. This bug does not occur with mouse input. I don't know why.   Here is is my script which is run from a DoFile in my XNA Update loop.  if (gameController.inputController:Pressed(Keys.Space)) then Console.WriteLine("pressed");     if (mainMenu.cursorState == "look")     then         mainMenu.cursorState = "talk";         Console.WriteLine(mainMenu.cursorState);     else         mainMenu.cursorState = "look";         Console.WriteLine(mainMenu.cursorState);     end end  the Pressed function is used to just check the previous KeyboardState and the current Keyboard state so that we know the key has been pressed and released instead of just being pressed.
  2. Using XNA enum type in Lua

    Okay here's the weird thing....   The if block IS executing but only if I hold down the Space key for a while. It's like there is some lag in the program or something. Anyone know whats happening here? This script is being executed in the XNA Update loop.
  3. Using XNA enum type in Lua

    if I change that to key:IsKeyDown the error doesnt happen but the if block still doesnt get executed which means there must still be some misrepresentation of the enumtype.
  4. I am trying to use the Keys enum type while scripting with Lua.   In C#, I have the following definitions: luaVM["Keys"] = Activator.CreateInstance(typeof(Microsoft.Xna.Framework.Input.Keys)); luaVM["key"] = Keyboard.GetState(); But when compiling the lua script I get error "invalid arguments to method: KeyboardState.IsKeyDown" on the following line in my script: if (key.IsKeyDown(Keys.Space)) then  
  5. Creating NET object in Lua

    Yeah, you'll note in my last post I said tried both strings. I don't know if it's having trouble finding the assembly. I do know that error reporting with load_Assembly is non-existent. You can type nonsense in the string and it won't throw an exception. Not to worry, a temporary solution is to write a function in C# that returns a newly created instance of the object you want. That's not creating it in Lua but it works.....for now.
  6. Creating NET object in Lua

    Thanks folks but I saw that format of calling the import type in other posts and already tried that. Both approaches return nil on the import_type call. Also, if you use import_type on "System.Console" , for example, you can directly use WriteLine on the type variable. This is probably because it is defined as static.   I think the string I am passing to import_type or load_assembly must be wrong somehow. I've tried passing either "PointClick" and "PointClick.GameController" to load_assembly but it still returns nil on import_type("PointClick.GameController")
  7. Creating NET object in Lua

      Sorry gOb2 was a typo I did not notice. But the problem seems to be that luanet.import_type("PointClick.GameController") is returning nil and I have no idea why. import_type does not return nil for existing NET references like "Microsoft.XNA.Framework" or "System.Console". The problem seems to come when trying to access or create custom classes in Lua. if gObj is registered with the Lua statemachine in C#, I can access its string type properties for example, but not a custom type. I think this is because custom types register as a black box userdata type in Lua. I hope somebody can help since there is practically zero support for Lua online. There are some sites that discuss how to handle userdata types in Lua of different implementations with C++ but that doesn't really work with C#.   Btw, sorry for the empty quote box above. Can't delete it in editor.  
  8. Hi folks,   I'm having trouble creating a C#.NET object in Lua. I can do this no problem with the System.Console type but this object has another object in it's constructor so that may be the issue. I hope you guys can help.   Here is my c# code:   public class GameController : DrawableGameComponent     {         public string gcname;           public GameController(Game game)             : base(game)         {             this.gcname = "Pulled from gc";         }       }   Here is my lua code: luanet.load_assembly ("PointClick.GameController"); luanet.load_assembly ("Microsoft.Xna.Framework.Game"); luanet.load_assembly ("Microsoft.Xna.Framework");   game = luanet.import_type("Microsoft.Xna.Framework.Game"); gObj2 = luanet.import_type("PointClick.GameController");     Console.WriteLine(gObj.gcname);     --gObj2=gOb2:GameController(game);   gObj2.gcname=" to this";   gObj= gObj2;     I get the error "attempt to index global 'gOb2' (a nil value)" on the line "gObj2.gcname=to this" Thanks in advance.
  9. If I have a dictionary of the type <String, CustomClass> in C# can I access that along with the customClass and its methods and fields inside Lua? If so, please let me know how.
  10. This was just a test example. For my game, MyTexture would be extended into a GameEntity class and each one would be polled in the current Screen class's Update loop to see if it had been clicked. I don't get what you mean by using C# Window event. What I am doing is currently within an XNA framework so I don't know if it applies since I don't have access to a Window object.   Also, a disadvantage of using the += operator for assigning anew method is that I can't change it without using -= on the previous method and for that I need to know the method's name. This could probably be solved by using a delegate in MyTexture and simply assigning/changing a method name as needed.
  11. Here are some excerpts of my code:   public class MainMenu : Screen { public override void LoadContent() { position = new Vector2(100, 150); start = new MyTexture("Textures/Start",position,this.gameController); start.ClickEvent += new EventHandler(this.MoveText); } public void MoveText(object sender, EventArgs e) { MyTexture t = (MyTexture)sender; Vector2 newpos = new Vector2(start.position.X + 50, start.position.Y - 50); t.Move(newpos); } } class MyTexture { public EventHandler ClickEvent; public void ClickHappened() { if (gc.inputController.Clicked()) { if (bounds.Contains(gc.inputController.currMouseState.X, gc.inputController.currMouseState.Y)) { if (ClickEvent != null) ClickEvent(this, null); } } } } What is dont understand is how to trigger ClickHappened without constantly polling it. If I have to always poll it then I wont need an event handler, I can just turn it into a bool function and call MoveText if it returns true;
  12. Vortez thanks for sending me your SDK but you are attaching your MsgProc function to your lpfnWndProc parameter of your Window class. I am doing this in C# XNA so I don't know what the equivalent  for that would be in the XNA framework.   Juliean, you say when my texture is clicked the delegate would fire its attached function. But how would I know if the texture has been clicked without constantly polling a function to see if Mousedown has occurred within the bounds of the texture?
  13. I have looked online for custom events and have been a little confused by the example code. Many of them seem to set to set the event as the changing of a variable. This is a one time event. But what if you want to check for an event that could be true at any time?   I have a custom texture class that has a boolean function isClicked that returns true if the the texture has been clicked onscreen. I am using this in XNA so I constantly check if this this function returns true or not. But is there any way to create an event handler that will run a function when this has been clicked without constantly polling the function. If I have multiple textures onscreen this could affect performance so I would like to know if I can have an event handler that will fire without always running the the isClicked function? I doubt this is possible but just wanted to test the waters.....
  14. Hi folks, I am working on a point and click adventure game in XNA and have decided to implement scripting via LuaInterface to keep my code more flexible. The thing is this is my first major game and also my first intro to scripting. The info available on the net seems scarce.   So I was wondering how I would implement the scripting in my engine. My game is composed of a list of Screens with Update/Draw loops, that is composed of a list of MyTextures that will have animation and state content but currently only have the Draw,isClicked ,isOver,Move methods. I am not currently implementing a conversation manager so the only events MyTexture currently fire are whether the mouse has been clicked or hovered over them. Currently, the engine is at an extremely basic level where i can create/remove multiple screens, turn off their Update/Draw loops, each Screen Update loop has hardcoded checks for input via the MyTexture.isClicked boolean function and the Screen Draw loop calls the MyTexture.Draw which draws the texture at its defined position which can be changed by the MyTexture.Move method.   MyTexture is the closest thing I have to a GameEntities class right now. But I am wondering how to implement Lua into all of this. Do I create a seperate script for each MyTexture object that will handle Look, Use, Talk events? Or do I create an all encompassing script in my Screen's Update loop that checks for events on each MyTexture? The first method will require juggling more files but seems cleaner while the second methood seems more messy especially handling something basic like input in Lua. Can Lua handle custom C# events? Do I create a separate Lua state machine for each MyTexture object or just one for the Screen object? Can I create compiled versions of my lua scripts that LuaInterface can run? And so forth...   Please help and thanks in advance.....    
  15. Generic C# delegates

    Glad I could inspire you. And thank YOU for sticking with this thread through all my incessant questioning. I'll probably open up a new thread regarding my engine and it's implementation of LuaInterface. Regards....