Forums

irrlicht problems

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

irrlicht problems

Postby mindstormss » Sun Oct 19, 2008 3:09 pm

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?
Eat a live toad the first thing in the morning and nothing worse will happen to you the rest of the day.
mindstormss
 
Posts: 8

Re: irrlicht problems

Postby Charles » Sun Oct 19, 2008 3:38 pm

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
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: irrlicht problems

Postby mindstormss » Sun Oct 19, 2008 5:33 pm

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 :)
Eat a live toad the first thing in the morning and nothing worse will happen to you the rest of the day.
mindstormss
 
Posts: 8

Re: irrlicht problems

Postby Charles » Sun Oct 19, 2008 7:46 pm

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: irrlicht problems

Postby mindstormss » Sun Oct 19, 2008 8:48 pm

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...
Eat a live toad the first thing in the morning and nothing worse will happen to you the rest of the day.
mindstormss
 
Posts: 8

Re: irrlicht problems

Postby Charles » Sun Oct 19, 2008 9:32 pm

That's interesting information. I'll take a look this week.

Glad to hear the workspace installer is working for you.

-Chuck
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: irrlicht problems

Postby Charles » Fri Oct 24, 2008 11:06 pm

Fixed in development.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 116 guests

cron