Forum Replies Created
-
AuthorPosts
-
Playing with C#, using override and virtual:
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233[crayon-5cba15ca4dc1c482364625 inline="true" ]using System;namespace test{class Program{public static void Main(string[] args){new Test();Console.ReadKey(true);}}class Test:Game2d {public Test() {Console.WriteLine("Test ctor");}public override void startup() {Console.WriteLine("Test startup");}}class Game2d {public Game2d() {Console.WriteLine("Game2d ctor");this.startup();}public virtual void startup() {Console.WriteLine("Game2d startup");}}}Outputs:
[/crayon]Monkey123[crayon-5cba15ca4dc23397922529 inline="true" ]Game2d ctorTest startupTest ctorNot using override and virtual keywords:
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233[crayon-5cba15ca4dc28334127646 inline="true" ]using System;namespace test{class Program{public static void Main(string[] args){new Test();Console.ReadKey(true);}}class Test:Game2d {public Test() {Console.WriteLine("Test ctor");}public void startup() {Console.WriteLine("Test startup");}}class Game2d {public Game2d() {Console.WriteLine("Game2d ctor");this.startup();}public void startup() {Console.WriteLine("Game2d startup");}}}Outputs:
[/crayon]Monkey123[crayon-5cba15ca4dc2e483248640 inline="true" ]Game2d ctorGame2d startupTest ctor[quote]Well, most languages except c++ (and I think Java gives an error).[/quote]
Well I always thought C++ was a bit odd
Java outputs:
[/crayon]Monkey1234[crayon-5cba15ca5537f055103330 inline="true" ]Game2d - Ctor...Test - startupGame2d - startTest - Ctor...Run the code in the above post, pure Java and no errors…
This looks like a bug to me. In most languages the extended version of startup should be called…
Java:
[/crayon]Monkey1234567891011121314151617181920212223242526272829303132333435[crayon-5cba15ca58c82325011896 inline="true" ]class Testing {public static void main(String[] args) {Testing t = new Testing();}public Testing() {Test c = new Test();}private class Test extends Game2d{public Test() {System.out.println("Test - Ctor...");}public void startup() {System.out.println("Test - startup");}}private class Game2d {public Game2d() {System.out.println("Game2d - Ctor...");this.startup();start();}public void start() {System.out.println("Game2d - start");}public void startup() {System.out.println("Game2d - startup");}}}Outputs:
[/crayon]Monkey1234[crayon-5cba15ca58c88650774098 inline="true" ]Game2d - Ctor...Test - startupGame2d - startTest - Ctor...MX1:
[/crayon]Monkey1234[crayon-5cba15ca58c8d277945071 inline="true" ]Game2d - CtorTest - startupGame2d - startTest - CtorMX2:
[/crayon]Monkey1234[crayon-5cba15ca58c92901260392 inline="true" ]Game2d - CtorGame2d - startupGame2d - startTest - CtorThanks for the reply Mark, I had already implemented the GetScreen method before I posted. In MX1 we could override Map.Get, any reason why you have decided to make it final in MX2?
Thanks for the detailed explanation.
Coming from C#, I’m more use this this explanation of when to use Struts vs Classes:
https://msdn.microsoft.com/en-us/library/ms229017(v=vs.110).aspx
On this page http://monkey2.monkey-x.com/language-reference/
Mark states:
Structs are very cheap to create as they are allocated ‘on the stack’ which is effectively a free operation and has no impact on garbage collection.
My C++ is very rusty… I thought the one of the main differences between a struct and a class was the struct went on the stack and the class went on the heap, along with that you can compare struct by value and classes by reference.
We’ll have to test a really large project and see if the size goes up too much.
I’m loving the current speed of MX2 compile times
(Oh BTW I’ve noticed that the “CODE” tag now expands double quotes)
Fair enough…
Let’s me get this straight: So it’s called ‘mojo’ in Monkey(X?)2… and you talk about ‘mojo2’ in your blog… and it’s more like ‘mojo2’ in MonkeyX1
Ah… yes…
Mark talks about mojo2 in the blog: http://monkey2.monkey-x.com/2016/05/07/little-update/
Mojo2 has been massively cleaned up and mx2-ified but should still remain largely recognizable to mx1 mojo2 users.
So in MX2 within code, its “mojo”:
Monkey123#Import "<mojo>"Using mojo..See it even confused me!
Rename to “Voodoo” to make it totally clear
Still fails in v0.009:
Monkey12345678910Function Main()Print "Step 2:"For Local x:Int = 1 To 10 Step 2Print xNextPrint "Step -1:"For Local x:Int = 5 To 1 Step -1Print xNextEndWhich outputs the following:
Monkey12345678910111213141516171819"H:/Projects/monkey2/bin/mx2cc_windows" makeapp -target=Desktop -config=Debug "H:/Projects/monkey2/hello-world.monkey2"MX2CC V0.009***** Building app 'H:/Projects/monkey2/hello-world.monkey2' *****Parsing...Semanting...Translating...Compiling....Linking H:/Projects/monkey2/hello-world.buildv009/desktop_debug_windows/hello-world.exeRunning H:/Projects/monkey2/hello-world.buildv009/desktop_debug_windows/hello-world.exeStep 2:13579Step -1:Done.Function Main is the starting point for all MonkeyX’s (1 & 2) application. You can put anything in there you like (as long as its valid MX2).
When I tested the negative step on v0.008 it doesnt do anything…
Nice!
I get this error when trying to upload images: “You don’t have permission to attach files to this post.”
Leave out the ‘End’…. which ‘End’?
Getter/Setter:
Monkey123456789101112131415161718192021222324#Import "<std>"#Import "<mojo>"Interface FooProperty Prop:Int()Setter( p:Int )EndClass Bar Implements FooField value:IntProperty Prop:Int()Return valueSetter(value:Int)Self.value = valueEndEndFunction Main()Local foobar:Foo = New BarPrint("foobar.Prop = " + foobar.Prop)foobar.Prop = 1Print("foobar.Prop = " + foobar.Prop)EndGetter Only:
Monkey12345678910111213141516171819#Import "<std>"#Import "<mojo>"Interface FooProperty Prop:Int()EndClass Bar Implements FooField value:IntProperty Prop:Int()Return valueEndEndFunction Main()Local foobar:Foo = New BarPrint("foobar.Prop = " + foobar.Prop)EndDid I miss something here?
Ah found the Unsubscribe button
(top right in a light blue colour)
-
AuthorPosts