first I want to say that I think Cobra looks like a fantastic language, as it combines all my favourite features from other languages.
Now, onto the problem:
I'm trying to create a small game, Tic Tac Toe to be exact, and for this I have chosen SdlDotNet. In C# I've managed to make a window pop up, which you can close (I know, extraordinarily cool, huh?), but I can't seem to get this to work in Cobra. I do manage to get a window to pop up, but I can't close it or use any other events. Here's my code:
- Code: Select all
use SdlDotNet.Core
use SdlDotNet.Graphics
class App
def main is shared
App().go
def init
Video.setVideoMode(640, 480)
Video.windowCaption = "Hello from SdlDotNet and Cobra"
def go
listen Events.quit, ref .quit
Events.run
def quit(sender as Object, args as EventArgs)
Events.quitApplication
Which doesn't work, I get the error 'Cannot access instance member "quit" on type "Events". Make the member "shared" or create an instance of the type.'
Here's my C# code (which works):
- Code: Select all
using SdlDotNet.Core;
using SdlDotNet.Graphics;
public class Application {
[System.STAThread]
public static void Main() {
(new Application()).Go();
}
public Application() {
Video.SetVideoMode(640, 480);
Video.WindowCaption = "Tic Tac Toe";
}
public void Go() {
Events.Quit += new System.EventHandler<QuitEventArgs>(this.Quit);
Events.Run();
}
private void Quit(object sender, QuitEventArgs e) {
Events.QuitApplication();
}
}
Now, I've tried creating an instance of Events as the error instructed me to, but that does not work. I don't understand what it means by "making it shared", if it means making it static, isn't it already? I haven't created any instance in the C# example? Any tips on what I should do? I don't even know if I'm using the "listen" correctly.