Page 1 of 1

irrlicht problems

PostPosted: Sun Oct 19, 2008 3:09 pm
by mindstormss
I am really enjoying this language, and have decided to try to use the .net wrapper for irrlicht with cobra. Everything seems to be working, but for some reason cobra will not let me do this:
Code: Select all
device.onEvent += OnEventDelegate(ref .device_onEvent)

it errors with
irrlichtExample.cobra(17): error: Cannot apply PLUS_EQUALS to OnEventDelegate.
Try finding a method that performs this function.

but the equivalent c# works:
Code: Select all
$sharp('device.OnEvent += new OnEventDelegate(Device_onEvent);')

here is my entire example program:
Code: Select all
# .args. -ref:Irrlicht.NET

use IrrlichtNETCP

class Program
   shared
      var exit as bool = false
      def main
         device as IrrlichtDevice? = IrrlichtDevice(DriverType.Direct3D9,Dimension2D(800,600),32,false,false,false,false)
         if device is nil
            return #the device could not be opened
            
         caption = 'this is a test'
         device.windowCaption = caption
         
         $sharp('device.OnEvent += new OnEventDelegate(Device_onEvent);')
         #device.onEvent += OnEventDelegate(ref .device_onEvent)
         #errors with:
         #irrlichtExample.cobra(17): error: Cannot apply PLUS_EQUALS to OnEventDelegate.
         #Try finding a method that performs this function.
         #But it works fine with the c# equivalent???
         
         scene = device.sceneManager
         driver = device.videoDriver
               
         lastFPS = -1
         while device.run and not .exit
            driver.beginScene(true, true, Color.gray)
            scene.drawAll
            driver.endScene

            fps = driver.fps
            if lastFPS <> fps
               device.windowCaption = caption+' FPS: [fps]'
               lastFPS = fps
         device.dispose
      
      def device_onEvent(ev as Event) as bool   #allows for keypresses/mouse presses
         if ev.type==EventType.KeyInputEvent and ev.keyPressedDown and ev.keyCode==KeyCode.Escape
            .exit = true
            return true
         return false
      

Am I missing something?

Re: irrlicht problems

PostPosted: Sun Oct 19, 2008 3:38 pm
by Charles
listen device.onEvent, ref .device_onEvent

See also: Cobra 0.7 Release Notes

Also, it looks like IrrlichtDevice(...) is a constructor in which case it cannot return nil/null (C#/.NET doesn't allow it). The normal thing in .NET is that the constructor will throw an exception. You can let that be or catch it to provide recovery or a user-friendly error message.

Also, in the latest compiler out of Subversion, you can replace:
# .args. -ref:Irrlicht.NET
use IrrlichtNETCP

# with:

use IrrlichtNETCP from Irrlicht.NET

...if you want to.

Also, the WinForms code in ObjectExplorer-WinForms.cobra offers more examples of event handling. Although it fails to take advantage of Cobra's new extended initialization:
b = Button(text='Save', dock=DockStyle.Top)

HTH!

Keep asking questions. It helps us realize where our docs and examples are weak.

-Chuck

Re: irrlicht problems

PostPosted: Sun Oct 19, 2008 5:33 pm
by mindstormss
Thanks,

Another question: when I use the Vector3D() class in Irrlicht, it complains if I have Vector3D(.2f,.2f,.2f) because it can't convert from double to float...It appears as if cobra's float is the double elsewhere, but I can't seem to figure out how to get a real float...

*edit* nevermind, I found it... floats are by F. The only reason I found this was because I started playing around with it, and the error message said to use F instead of f...These things really need to be mentioned somewhere to make it more newbie oriented, as you seem to tout as one of your strengths.

*edit2* on the other hand, putting an F as a suffix gives an error too... (expecting EOL but got "F"(ID) instead)
it looks like the proper suffix is actually "f32"...personally, 0.2F would look cleaner to me than 0.2f32

Also, I think the forum search parameters should be relaxed, it wouldn't let me search for float or double!! (or decimal). In fact, I think it has only worked for me once.

I would like to thank everyone who has worked on this amazing little language and for helping me out with it. :P


I come from the python world of nice ambiguity :)

Re: irrlicht problems

PostPosted: Sun Oct 19, 2008 7:46 pm
by Charles
Note that Cobra is like most other languages in that decimal numbers need a leading digit, even if it's zero: 0.2f32

Btw, are you using Cobra 0.8 (the last release) or Cobra from Subversion/svn?

I don't understand what made you think that F was the solution. Can you throw me some sample code that did that and what message you got?

Is float32 the prevalent fractional type in your program? Because if it is, you can say:

cobra -number:float32 ...

And then "0.2" will be a float32 instead of a decimal. See cobra -h

It's unlikely I would use f vs. F to determine the literal size. Which is which? What happens if we ever get a float96 or float128?

Also, I'm playing with the idea of "context sensitive fractionals" meaning that if there was an unambiguous determination of the type for a literal such as "0.2" then Cobra would simply use it. So if you said "foo.bar(0.2)" and there is only one .bar that takes a fractional type such as float32, then Cobra would consider "0.2" to be a float32. However, in light of the -number: option, I don't know how much this is needed.

Re: irrlicht problems

PostPosted: Sun Oct 19, 2008 8:48 pm
by mindstormss
The error I was getting:
irrlichtTest.cobra(22): error: Literal of type double cannot be implicitly converted to type "float"; use an "F" suffix to create a literal of this type

A sample script that throws this error
Code: Select all
class Test
   def init
      a as float32 = 0.2f


strangely enough doing
Code: Select all
class Test
    var a as float32 = 0.2f

doesn't give the same error...

I am using the svn code from today, in fact have been tracking and updating the new installation from workspace thing your doing, and can say that it seems to be working here...

Re: irrlicht problems

PostPosted: Sun Oct 19, 2008 9:32 pm
by Charles
That's interesting information. I'll take a look this week.

Glad to hear the workspace installer is working for you.

-Chuck

Re: irrlicht problems

PostPosted: Fri Oct 24, 2008 11:06 pm
by Charles
Fixed in development.