Forum Replies Created
-
AuthorPosts
-
November 6, 2016 at 6:44 pm in reply to: Something like this json config manager useful to anyone as a module? #4821
Ok that’s good to know!
November 6, 2016 at 1:39 pm in reply to: Something like this json config manager useful to anyone as a module? #4810I was tempted but didn’t know if it was safe to use the Reflection stuff yet. Also what overhead does using monkey2 reflection bring? I already noticed someone mentioning that their file size had increased dramatically.
Awesome Mark. Notepad++ is a good baseline to go from!
Nerobot, I will give ted2go a try!
Ah I see, hopefully its open for convincing?
Well this seems like a bug to me, in that every times it happens I get the urge to leave a bug report. It can be ignored, but after a few weeks now, it still seems like a fault instead of a feature. I spend the majority of my time in Windows and 95% of text editors/IDE’s I have used, tab all lines selected. So I guess that makes this particular feature seem very alien.
Is this perhaps something that can be added to an “advanced” settings dialog? It seems like one of those things that is highly related to users personal preference, instead of something that should be hard coded into the design.
What if Stack (and others) had a new method for running an operation for each item in series.
For example:
Monkey1234567891011121314151617181920212223242526272829303132'this would be a member of StackMethod Do<T>:Void(callback:Void(item:T))'get list of all itemsLocal items := ToArray()For Local index := 0 Until items.Lengthcallback(items[index])NextEnd'example codeClass ItemField name:StringMethod New(name:String)Self.name = nameEndEndFunction Main:Void()Local items := New Stack<Item>()items.Push(New Item("apple"))items.Push(New Item("orange"))items.Push(New Item("tree"))items.Push(New Item("keyboard"))'slow but works!items.Do(Lambda(item:Item)items.Remove(item)End)EndThis could be used for a lot more then just removing!
Monkey123456789101112131415161718192021222324252627'example codeClass ItemField name:StringField hitPoints:IntMethod New(name:String, hitPoints:Int)Self.name = nameSelf.hitPoints = hitPointsEndEndFunction Main:Void()Local items := New Stack<Item>()items.Push(New Item("apple", 0))items.Push(New Item("orange", 3))items.Push(New Item("tree", 2))items.Push(New Item("keyboard", 0))Local text:Stringitems.Do(Lambda(item:Item)If item.hitPoints <= 0text+= ", "+item.name+" is dead"EndifEnd)Print textEndAlso clearly this is not the most efficient way to iterate and do stuff, but it works.
In these example the Do creates a list of items at the time of calling, so this is then safe to iterate over. It generates junk, but this could be optimised. Or a safe/unsafe flag could be specified, causing the loop to iterate directly, or create the array first with safe mode. e.g.
Monkey12345678910111213141516Method Do<T>:Void(callback:Void(item:T),safe:bool= False)If safe'iterate safe'get list of all itemsLocal items := ToArray()For Local index := 0 Until items.Lengthcallback(items[index])NextElse'iterate unsafeFor Local index := 0 Until _lengthcallback(_data[index])NextEndifEndAnother example:
Monkey123456789101112131415161718192021222324252627282930313233Class ItemField name:StringField hitPoints:IntMethod New(name:String, hitPoints:Int)Self.name = nameSelf.hitPoints = hitPointsEndEndFunction Main:Void()Local items := New Stack<Item>()items.Push(New Item("apple", 0))items.Push(New Item("orange", 3))items.Push(New Item("tree", 2))items.Push(New Item("keyboard", 0))Local currentOperation: = Operation1items.Do(currentOperation)EndFunction Operation1:Void(item:Item)item.name = "NO"EndFunction Operation2:Void(item:Item)item.name = "YES"EndFunction Operation3:Void(item:Item)item.name = "MAYBE"EndIts a bit later then planned, but I have created a basic project to show how the importing from parent directory is failing.
I get duplicate identifier errors. It appears that #import “foo.monkey2” and #import “../foo.monkey2” are not getting treated as the same file.
Really cool!
Yeah it is very mmf esque! surprising really as I do a lot of stuff for Clickteam these days
if it’s any good to release I will do so, otherwise will release as source so people can make use of it
That’s strange! I shall have another go tomorrow, see if I can isolate it an example.
Phew!
I would actually be pretty impressed if we managed to create the same game!
Cheers! ”Tis good to be back messing with monkeys again!
I do hope we are not making the same game as well gcmarijn
That is good news! Might be worth adding an example to the Lambda docs. I was going to do it in the online Manual, but it looks like comments are only available for modules?
Here is how I am using it, very handy!
Monkey1234567891011121314151617181920212223Method LoadAtlas:Atlas(path:String)'check if it exists alreadyLocal atlas := atlases[path]'do we need to load it?If atlas = Null'yup, load itatlas = Atlas.Load(path)If atlas'add discarded event to atlasatlas.OnDiscarded += Lambda()atlases.Remove(path)End'now cache itatlases[path] = atlasEndifEndif'return it nowReturn atlasEndWow just looked over this, impressive stuff
October 18, 2016 at 10:33 pm in reply to: Textfield doesn't lose focus when other gadgets are interacted with #4533Ok I have created something that will reproduce. Now that I have isolated it, it turns out that it is actually a bug (and not my own user error) .
Steps:
- press “item2” button
- select the text field and position the cursor at the end of the text
- press “item1” button
- start typing on the keyboard
- CRASH
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162#import "<std>"#import "<mojo>"#import "<mojox>"Using std..Using mojo..Using mojox..Class MyWindow Extends WindowField currentItem:ItemClass ItemField name:StringMethod New(name:String)Self.name = nameEndEndMethod New()Super.New("Bug",640,480,WindowFlags.Resizable)'create itemsLocal item1 := New Item("apple")Local item2 := New Item("long_item_name")'create text fieldLocal textField := New TextField()'create buttonsLocal button1:=New Button("item1")button1.Clicked=Lambda()currentItem = item1textField.Text = currentItem.nameEndLocal button2:=New Button("item2")button2.Clicked=Lambda()currentItem = item2textField.Text = currentItem.nameEnd'setup layoutLocal dockingView:=New DockingViewdockingView.AddView(button1,"left")dockingView.AddView(button2,"left")dockingView.ContentView=textFieldContentView=dockingViewEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndDidn’t realise that the Stack in monkey2 had been fleshed out so much, compared to monkey1/blitz! Very helpful!
-
AuthorPosts