Forum Replies Created
-
AuthorPosts
-
Enjoy coding and bla bla bla.
Forgot to say – I also removed IRC chat stuff to cooperate all community in a single place – Discord.
Hi guys.
There are some recent improvements in develop branch:
- New feature – using spaced indentation! Now, you can
- use spaces instead of tabs;
- set desired tab size (works with tabs and spaces);
- and even automatically fix “wrong” indentation.
- New feature – duplicate line or selected area with shortcut Ctrl+Shift+D (or just Ctrl+D on windows).
- Improved support of array type in code completion and code tree view.
- Completion list – some colors added into theme file:
- completion-list-selected – color of selected line
- completion-list-marked-bg– background color of highlighted chars
- completion-list-marked-text – foreground color of highlighted chars
- Added some preprocessor directives into completion list:
- __WEB_TARGET__ , __DEBUG__ , __RELEASE__ , __CONFIG__ , __MAKEDOCS__
- Added option “Rename folder” into Project browser context menu; and now open a *containing folder* by option “open on desktop” for files (don’t try to open file itself).
- Now storing latest opened tab in prefs dialog.
Attachments:
If we declare new sub-class JsonNull extends JsonValue and replace current NullValue with them – will it helps us to check if x is null-value w/o any stack-ish problems?
There may be a virtual method CompareTo:Int( value:JsonValue ) of JsonValue.
By default it will return -1.
And any sub-classes will override it.
Technically it will be the same as your functions above.
The difference is a way of call: json1.CompareTo( json2 ) in this case.
If we aware of nullability of json1, then we can use ?. operator.
Also in your code you check y=NullValue and return 1 if true, but x can be null itself and then we should get zero in result.
Sorry, I did’n understand about stack exploding reason.
If we use just functions like ones above – do we avoid stack exploding when using if Self.IsNull?
(JsonValue has a property IsNull.)
February 12, 2018 at 2:01 am in reply to: Simple cheat code class (My first attempt at using Monkey2!) #13615Did you try to check event.Type property inside your filter method?
If Not event.Type=EventType.KeyReleased Return
February 11, 2018 at 4:58 am in reply to: Simple cheat code class (My first attempt at using Monkey2!) #13607I’m lost on the App.KeyEventFilter though… There is no real documentation, and looking at the source has me scratching my head. It’s a field, but has a void return type?? And parameters? Wouldn’t that make it a method instead of a field? So confusing!
It is called “First class functions”, it’s a reference to a function/method stored in a variable.
It uses for signals, like KeyEventFilter, and you can to subscribe to it via += operator.
Monkey1App.KeyEventFilter += YourMethodWithTheSameSignatureAsKeyEventFilteror
Monkey12345App.KeyEventFilter += Lambda() ' lambda also with the same signature' you code hereEndAnd there is my variant of your class (with comments):
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687Class CheatSequenceField OnSuccess:Void() 'signal for completing this sequenceField numStrokes:Int ' Number of strokes in this sequenceField strokeCounter:Int ' Current stroke in the sequenceField strokes:Map<Int,SequenceStroke> ' Map of strokes in the sequenceField timeOut:Int ' millisecs timeoutField lastStrokeTimestamp:Int ' timestamp of last stroke input' Create a new cheat sequence' Default to a 1 second timeoutMethod New(thisTimeOut:Int=1000)numStrokes=0strokeCounter=0timeOut=thisTimeOutstrokes=New Map<Int,SequenceStroke>Enabled=True ' enable by defaultEnd' Add a stroke to the sequenceMethod AddStroke(strokeType:Int,strokeValue:Int)strokes.Add(numStrokes,New SequenceStroke(strokeType,strokeValue))numStrokes+= 1End MethodProperty Enabled:Bool()Return _enabledSetter( value:Bool )If value=_enabled Return_enabled=valueIf _enabledApp.KeyEventFilter+=KeyFilter ' subscribe to filterElseApp.KeyEventFilter-=KeyFilter ' unsubscribe from filterEndifEndPrivateField _enabled:Bool' our key filtering functionMethod KeyFilter( event:KeyEvent )' just pass event key into updateUpdate( event.Key )' and check does a user finish the sequenceLocal ok:=Success()If okOnSuccess() ' and emit event if successEndifEnd' The update method should be called any time a key is pressed' The OnKeyEvent is recommended' TODO: Add joystick and mouse supportMethod Update(thisKey:Int)If strokes.Get(strokeCounter).strokeType=Stroke.key And strokes.Get(strokeCounter).strokeValue=thisKeySelf.strokeCounter+=1Self.lastStrokeTimestamp=Millisecs()ElseSelf.strokeCounter=0EndifEnd Method' Check to see if the cheat is successful' This should be called each iteration through the game loopMethod Success:Bool()' We can't be successful if we timed out, lets handle that firstIf Millisecs()-lastStrokeTimestamp > timeOut And strokeCounter>0'We timed out, lets restartSelf.strokeCounter=0lastStrokeTimestamp=Millisecs()Else'If we've made it this far, lets see if we got it!If (Self.strokeCounter=Self.numStrokes)Self.strokeCounter=0Return TrueEndifEndifReturn FalseEndEndAs you can see I added OnSuccess signal that will be emitted right after user press key that finished the sequence.
To use this signal you should to subscribe to it, somewhere you create the sequence – inside of MyWindow::New() in your case:
Monkey1234567891011121314151617181920212223242526Method New()Super.New( "Cheat Code Test",640,480,WindowFlags.Fullscreen )lives=3contraCheat= New CheatSequence(1000)contraCheat.AddStroke(Stroke.key,Key.Up)contraCheat.AddStroke(Stroke.key,Key.Up)contraCheat.AddStroke(Stroke.key,Key.Down)contraCheat.AddStroke(Stroke.key,Key.Down)contraCheat.AddStroke(Stroke.key,Key.Left)contraCheat.AddStroke(Stroke.key,Key.Right)contraCheat.AddStroke(Stroke.key,Key.Left)contraCheat.AddStroke(Stroke.key,Key.Right)contraCheat.AddStroke(Stroke.key,Key.B)contraCheat.AddStroke(Stroke.key,Key.A)contraCheat.AddStroke(Stroke.key,Key.B)contraCheat.AddStroke(Stroke.key,Key.A)contraCheat.AddStroke(Stroke.key,Key.Enter)' subscribecontraCheat.OnSuccess+=Lambda()lives+=30EndEndAnd you should remove all usages of Succes and Update methods of CheatSequence from MyWindow code – they are private now!
So, now CheatSequence became more independant of Window class or any other – you just create sequence and fill it with keys and subscribe to its OnSucces.
February 10, 2018 at 11:07 am in reply to: Simple cheat code class (My first attempt at using Monkey2!) #13599A few notes:
- There is App.KeyEventFilter event you can subscribing to instead of OnKeyEvent – it allow us grab events outside of View class hierarchy
- You can also provide method AddStrokes( strokeType:Int,strokeValues:Int[] ) so that we can add sequences simplier way passing array.
I have dk2 (probably) I never used yet.
I have the idea for demo, maybe try to playing with it!
Look at Window::SwapInterval property.
Try to set it to 1.
Wow, good news!
When you omit key it passes as Null ?
You refer to this one right?
Yes. Your example is not good enough because I want to omit the key at all.
Also, if you pass False as a string parameter, you’ll get the string “False”, not an empty string,
and expression If key then... always be true.
I think you mean to pass Null here.
How about ‘+=’ instead? This looks much more logical to me.
It seems to be the only way here.
Brackets show us we deal with array, but += don’t.
But I don’t expect to break parser and our minds just because the PHP syntax.
Great!
Formatting? Processing!
I saw link to example of one side platform on Chipmunk homepage…
- New feature – using spaced indentation! Now, you can
-
AuthorPosts



