Forum Replies Created
-
AuthorPosts
-
Okay been using the site for a bit today, I like it but its too bright and the red text on a white background is a bit hard too read.
@abakobo – I think you need to link your user up with a gravatar account if I remember…
Looks good!
Is that Monkey logo the new official Monkey2 logo? There is another Monkeyish logo on the discord site too. I’m just finishing my game and want to use the correct one.
Could you try moving the crashtest_art_pack_01 to a path without spaces, currently its in ”C:/Users/Arolodo Carvalho/Documents/_Monkey2/crashtest_art_pack_01/pyro/bananas/”.
Eg C:/Monkey2-v1.1.09/crashtest_art_pack_01/pyro/bananas/
Cool! Didnt know you could use Java in the externs for Monkey2!
I’m getting this too using v1.1.09.
So this use to work?
In Java its doable, I’m not bothered either way just was trying out nerobot’s preferences code:
Monkey1Const Prefs:=Preferences.Get( AppDir()+"prefs.json" )I’m also getting run time error: “Attempt to invoke method on null instance” on the “If _prefs.Contains( path ) Return _prefs[path]” line…
That’s what I thought, but without the new you get “Attempt to invoke method on null instance” error…
Here is a slightly fixed simpler runnable example:
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215#Import "<std>"Using std..Const Prefs := New Preferences().Get(AppDir() + "prefs.json")Function Main()Print "Start"' try to get windowRect from prefsLocal x:IntPrefs.Get( AppDir()+"prefs.json" )If Prefs.Contains( "x" )Print "Prefs contains x"x= Prefs.GetInt("x")Print xElse' not found in prefs, set to defaultsPrint "Prefs does not contains x"x = Rnd(0, 100)Print xEndPrefs.PutValue("x", x)Preferences.SaveAll()Print "Finished"EndClass Preferences Final' globals'Function Get:Preferences( path:String )If _prefs.Contains( path ) Return _prefs[path]Local p:=New Preferences( path )_prefs[path]=pReturn pEndFunction SaveAll()For Local p:=Eachin _prefs.Valuesp.Save()NextEnd' signals'Field Changed:Void( key:String,value:Variant )' setters'Method PutValue( key:String,value:String )_data[key]=New JsonString( value )_dirty=TrueChanged( key,value )EndMethod PutValue( key:String,value:Bool )_data[key]=New JsonBool( value )_dirty=TrueChanged( key,value )EndMethod PutValue( key:String,value:Double )_data[key]=New JsonNumber( value )_dirty=TrueChanged( key,value )EndMethod PutValue( key:String,value:Int)_data[key]=New JsonNumber( value )_dirty=TrueChanged( key,value )EndMethod PutValue( key:String,value:JsonValue )_data[key]=value_dirty=TrueChanged( key,value )End' getters'Method GetString:String( key:String,defValue:String="" )Return _data.GetString( key,defValue )EndMethod GetBool:Bool( key:String,defValue:Bool=False )Return _data.GetBool( key,defValue )EndMethod GetInt:Double( key:String,defValue:Int=0 )Return _data.GetInt( key,defValue )EndMethod GetNumber:Double( key:String,defValue:Double=0 )Return _data.GetNumber( key,defValue )End' load'Method Load( path:String )_path=path_data=JsonObject.Load( path ) ?Else New JsonObject_dirty=FalseEnd' save'Method Save( path:String="" )If Not _dirty ReturnIf Not path Then path=_pathIf Not path ReturnSaveString( _data.ToJson(),path )_dirty=FalseEnd' raw data'Property Json:JsonObject()Return _dataEndMethod Contains:Bool( key:String )Return _data.Contains( key )EndPrivateField _data:JsonObjectField _path:StringField _dirty:BoolGlobal _prefs:=New StringMap<Preferences>' private constructors'Method New( path:String )Load( path )EndMethod New()EndEndClass JsonObject ExtensionMethod GetBool:Bool( key:String,defValue:Bool )Local json:=SelfReturn json.Contains( key ) ? json[key].ToBool() Else defValueEndMethod GetString:String( key:String,defValue:String )Local json:=SelfReturn json.Contains( key ) ? json[key].ToString() Else defValueEndMethod GetInt:Int( key:String,defValue:Int )Local json:=SelfReturn json.Contains( key ) ? Int(json[key].ToNumber()) Else defValueEndMethod GetNumber:Double( key:String,defValue:Int )Local json:=SelfReturn json.Contains( key ) ? Int(json[key].ToNumber()) Else defValueEndMethod FindValue:JsonValue( key:String )key=key.Replace( "\","/" )Local keys:=key.Split( "/" )Local json:=Self.DataLocal jval:JsonValueFor Local k:=0 Until keys.LengthIf Not json.Contains( keys[k] ) Return Nulljval=json[ keys[k] ]If k=keys.Length-1 ExitIf Not jval.IsObject Return Nulljson=jval.ToObject()NextReturn jvalEndEndClass JsonArray ExtensionFunction FromStrings:JsonArray( values:String[] )Local jvals:=New JsonValue[values.Length]For Local i:=0 Until values.Lengthjvals[i]=New JsonString( values[i] )NextReturn New JsonArray( jvals )EndEndI’m currently working on my entry for the Syntax Bomb’s Retro Competition and using Diddy2 as the main framework.

WIP Video:
gtdc.mp4Note: The code from nerobot, needs the extensions from this post: http://monkeycoder.co.nz/forums/topic/json-extensions/
I’m also getting run time error: “Attempt to invoke method on null instance” on the “If _prefs.Contains( path ) Return _prefs[path]” line…
Test code, I had to “hack” some of the features to crappy returns etc:
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326#Import "<std>"#Import "<mojo>"#Import "<mojox>"Using std..Using mojo..Using mojox..' imports'#Import "assets/"' try to load prefs from fileConst Prefs:=Preferences.Get( AppDir()+"prefs.json" )Function Main()New AppInstance()' try to get windowRect from prefsLocal rect:RectiLocal flags:=WindowFlags.ResizableIf Prefs.Contains( "windowRect" )rect=ToRecti( Prefs.GetJson( "windowRect" ) )Else' not found in prefs, set to defaultsrect=New Recti( 0,0,900,800 )flags|=WindowFlags.CenterEndifLocal wnd:=New MainWindow() ' "Prefs test",rect,flags ) ' <----- Main Window CTOR doesnt have paramswnd.CloseRequested+=Lambda()Prefs.PutValue( "windowRect",ToJson( wnd.Frame ) )Preferences.SaveAll()EndApp.Run()EndClass MainWindow Extends WindowField CloseRequested:Void()ProtectedMethod OnWindowEvent( event:WindowEvent ) OverrideIf event.Type=EventType.WindowCloseCloseRequested()EndifSuper.OnWindowEvent( event )EndEndClass Preferences Final' globals'Function Get:Preferences( path:String )If _prefs.Contains( path ) Return _prefs[path]Local p:=New Preferences( path )_prefs[path]=pReturn pEndFunction SaveAll()For Local p:=Eachin _prefs.Valuesp.Save()NextEnd' signals'Field Changed:Void( key:String,value:Variant )' setters'Method PutValue( key:String,value:String )_data[key]=New JsonString( value )_dirty=TrueChanged( key,value )EndMethod PutValue( key:String,value:Bool )_data[key]=New JsonBool( value )_dirty=TrueChanged( key,value )EndMethod PutValue( key:String,value:Double )_data[key]=New JsonNumber( value )_dirty=TrueChanged( key,value )EndMethod PutValue( key:String,value:JsonValue )_data[key]=value_dirty=TrueChanged( key,value )EndMethod PutValue( key:String,value:Color )_data[key]=value.ToJson()_dirty=TrueChanged( key,value )End' getters'Method GetString:String( key:String,defValue:String="" )Return _data.GetString( key,defValue )EndMethod GetBool:Bool( key:String,defValue:Bool=False )Return _data.GetBool( key,defValue )EndMethod GetNumber:Double( key:String,defValue:Double=0 )Return _data.GetNumber( key,defValue )EndMethod GetJson:JsonValue( key:String,defValue:JsonValue=Null )Return _data.GetJson( key,defValue )EndMethod GetColor:Color( key:String,defValue:Color=Color.Magenta )If _data.Contains( key )Return Color.FromJson( _data[key] )EndifReturn defValueEnd' load'Method Load( path:String )_path=path_data=JsonObject.Load( path ) ?Else New JsonObject_dirty=FalseEnd' save'Method Save( path:String="" )If Not _dirty ReturnIf Not path Then path=_pathIf Not path ReturnSaveString( _data.ToJson(),path )_dirty=FalseEnd' raw data'Property Json:JsonObject()Return _dataEndMethod Contains:Bool( key:String )Return _data.Contains( key )EndPrivateField _data:JsonObjectField _path:StringField _dirty:BoolGlobal _prefs:=New StringMap<Preferences>' private constructors'Method New( path:String )Load( path )EndMethod New()EndEndStruct Color ExtensionFunction FromHex:Color( hex:String )Local str:=hexLocal a:=1.0,r:=0.0,g:=0.0,b:=0.0If str.Length=4 '#RGBr=StringToULong( str.Slice( 1,2 ),16 )/15.0g=StringToULong( str.Slice( 2,3 ),16 )/15.0b=StringToULong( str.Slice( 3,4 ),16 )/15.0Else If str.Length=5 '#ARGBa=StringToULong( str.Slice( 1,2 ),16 )/15.0r=StringToULong( str.Slice( 2,3 ),16 )/15.0g=StringToULong( str.Slice( 3,4 ),16 )/15.0b=StringToULong( str.Slice( 4,5 ),16 )/15.0Else If str.Length=7 '#RRGGBBr=StringToULong( str.Slice( 1,3 ),16 )/255.0g=StringToULong( str.Slice( 3,5 ),16 )/255.0b=StringToULong( str.Slice( 5,7 ),16 )/255.0Else If str.Length=9 '#AARRGGBBa=StringToULong( str.Slice( 1,3 ),16 )/255.0r=StringToULong( str.Slice( 3,5 ),16 )/255.0g=StringToULong( str.Slice( 5,7 ),16 )/255.0b=StringToULong( str.Slice( 7,9 ),16 )/255.0ElseReturn Color.MagentaEndifReturn New Color( r,g,b,a )EndMethod ToJson:JsonValue()Return New JsonArray( New JsonValue[]( New JsonNumber( r ),New JsonNumber( g ),New JsonNumber( b ),New JsonNumber( a ) ) )EndFunction FromJson:Color( json:JsonValue )If json.IsArrayLocal arr:=json.ToArray()Return New Color( arr[0].ToNumber(),arr[1].ToNumber(),arr[2].ToNumber(),arr[3].ToNumber() )ElseReturn FromHex( json.ToString() )EndifEndEndClass JsonObject ExtensionMethod GetJson:JsonValue( key:String,defValue:Bool )Local json:=SelfReturn New JsonValue ' <------- crap Return value FIXMEEndMethod GetBool:Bool( key:String,defValue:Bool )Local json:=SelfReturn json.Contains( key ) ? json[key].ToBool() Else defValueEndMethod GetString:String( key:String,defValue:String )Local json:=SelfReturn json.Contains( key ) ? json[key].ToString() Else defValueEndMethod GetInt:Int( key:String,defValue:Int )Local json:=SelfReturn json.Contains( key ) ? Int(json[key].ToNumber()) Else defValueEndMethod GetNumber:Double( key:String,defValue:Int )Local json:=SelfReturn json.Contains( key ) ? Int(json[key].ToNumber()) Else defValueEndMethod FindValue:JsonValue( key:String )key=key.Replace( "\","/" )Local keys:=key.Split( "/" )Local json:=Self.DataLocal jval:JsonValueFor Local k:=0 Until keys.LengthIf Not json.Contains( keys[k] ) Return Nulljval=json[ keys[k] ]If k=keys.Length-1 ExitIf Not jval.IsObject Return Nulljson=jval.ToObject()NextReturn jvalEndEndClass JsonArray ExtensionFunction FromStrings:JsonArray( values:String[] )Local jvals:=New JsonValue[values.Length]For Local i:=0 Until values.Lengthjvals[i]=New JsonString( values[i] )NextReturn New JsonArray( jvals )EndEndit might be time to drop angle
For casual games DirectX is still the major player and I think it would be a mistake to drop it.
Very nice!
One of the requirements of Steam is to state the minimum requirements of the game being published, what would the minimum requirements be for a Monkey2 game?
What does MX1 and CerberusX spit out?
No worries! Sometimes its hard to keep up with all the changes – thanks for helping!
-
AuthorPosts