Adventure Window - Game Creator

Monkey Targets Forums/User Targets/Adventure Window - Game Creator

time-killer-games(Posted 2013) [#1]
I am making a game engine with monkey (it's sort of like a target but not precisely), but there are two things I need before I can release it. First thing - I am in dire need of a reading INI file functions. I found a script on the forum and tried it, modified it, never figured out how to actually use it.

All I need is something like - "INIRead(file, section, key,default)"
That's it. But I can't seem to figure it out at all.

The second thing - have have no idea how to use the 3D module it makes no sense to me. I tried running the examples and I get errors.

Thanks!
TKG


Goodlookinguy(Posted 2013) [#2]
I can't comment on the 3D module, but as far as INI stuff goes, I ported a BlitzMAX ini reader/writer a while ago. Which is the script I assume you're referring to.

http://www.monkeycoder.co.nz/Community/posts.php?topic=3077

It's extremely easy to use.

file.ini
[Example]
rect = 0, 0, 40, 20
some value = "Hello World"

[More]
ini reader = 18.45

Load it
Local ini:Ini = Ini.Load(LoadString("file.ini"))

Get and print value
Print ini.GetFloat("ini reader", "More")

Output
18.45



On a side note, if you're having problems reading and/or running code, jumping straight to a game engine should not be your goal at the moment. I've been aiming to create a game engine for some 5 years now and have around 12 years of programming experience. It's much harder than it seems from the outside. It's better, and generally quicker, to just create games. At the most, little tools for your specific game are fine, but a game engine requires that the code be extremely flexible and modular in design, which is not an easy task.


time-killer-games(Posted 2013) [#3]
Finally got it working, thanks!

Actually this game engine is 100% done. I originally wrote it in GameMakerLanguage, which has built-in INI functions. I'm translating the code equivalents into monkey code for the sake of adding more supported platforms...

It is understandable to think I have no understanding of how to program after seeing this topic, but that isn't the case. I'm more used to C++ like languages such as GML. Monkey on the otherhand seems to be more like VisualBasic (perhaps Delphi?) anyway thanks for the help.

I the few error fixes to do and I'll be ready to share my end result with you guys here, (hopefully on the GameMaker Community as well)...

Cheers!
TKG


Goodlookinguy(Posted 2013) [#4]
Oh, I see. That's my bad. As for Monkey, it's like a cross between the look of BASIC and the structure of Java/C#.

Anyways, glad you got it working.


MikeHart(Posted 2013) [#5]
Interesting project and for sure will give it a spin once it is released.


time-killer-games(Posted 2013) [#6]
New problem, array index out of bounds - I get this error on the html5, flash, and python targets. Have no idea how to fix it - help?



AdamRedwoods(Posted 2013) [#7]
OnRender() code should be kept to a minimum and i think some of the code can be better formatted, too hard for an outsider to read. reformat it and then we can help.

also use "codebox" instead of just "code"


rIKmAN(Posted 2013) [#8]
I really hope the forum has screwed up the formatting of your code?

If not you should start using indentation to make your code easier to read, then re-post it.


Paul - Taiphoz(Posted 2013) [#9]
yeah all that logic code should be in update render should really just hold the code that actually renders stuff and does the drawing.

and I second the please format your code, the site has syntax highlighting if you use the right codebox bbcode , which will help a lot as well.


time-killer-games(Posted 2013) [#10]
I can easily indent it and I'm doing so as we speak. why I originally had it like that is because I translated it from my Game Maker code which uses braces {} instead of "End" when the cursor clicks on an area of my code where there is a brace it shows me where the two braces open and close by highlighting them, and auto syntax error checks, thus making indention pointless. Since monkey doesn't work that way, on it...


Goodlookinguy(Posted 2013) [#11]
I didn't test any of the code, but just looking at it, it seems as if you have a misunderstanding of how scoping works. Most of those variables you're trying to use are in a local scope, which means that when the method/function is finished, those variables are freed from memory. What you're looking for is to initialize those variables as fields in the class scope.

Here's an example...
Class Example Extends App
    Field a:Int
    Field b:Int
    
    Method OnCreate:Int()
        a = 2
        b = 1
        
        Return 0
    End
    
    Method OnUpdate:Int()
        If a <> b
            a = b
        Else
            a = 2
        End
        
        Print a
        
        Return 0
    End
End



time-killer-games(Posted 2013) [#12]
Updating the code. Thanks but I can't test it ATM I'll let you know if that solves my issues... :D


time-killer-games(Posted 2013) [#13]
Haven't solved the indent problem yet, but I probably won't need to now that I'm getting no error messages. Here is my current project:

https://dl.dropbox.com/u/79893663/Shadows3D/MonkeyCoder-v6.0-AdventureWindowRunner-v0.9.zip

For you guys who are lazy like me here's the codebox:


It builds and runs on all targets supporting mojo. But here's hopefully my last issue:

I get a blank, black rectangle instead of my png, which is loaded from the INI. I don't know if there is something wrong with the file and path given in the INI or the code itself, or what the issue is exactly...

Thanks


Goodlookinguy(Posted 2013) [#14]
The INI "Load" function loads strings. "run.ini" needs to be wrapped in the "LoadString" function. That is, unless you've edited it.

Field ini:Ini = Ini.Load(LoadString("run.ini"))


Edit: Actually, I misread it. Those fields need to be initialized in the OnCreate method. Such as this example...

Class Example Extends App
    Field ini:Ini
    
    Method OnCreate()
        ini = Ini.Load(LoadString("run.ini"))
    End
End



time-killer-games(Posted 2013) [#15]

Still gives me a black rectangle instead of my image.
If it helps, here is my INI file:

Here is a video that displays what Adventure Window is supposed to do, which is the Game Maker version of Adventure Window:
https://www.dropbox.com/s/3rkbbgl0t0bpfv1/run.wmv

As you can see from the video it appears to make very nice 3D graphics. But that is actually a 2d picture textured onto a 3D cylinder. This is the only thing I need the minib3d module for - drawing a cylinder with the 3d camera smack dab in the middle to simulate Pre rendered 3d panoramas.


time-killer-games(Posted 2013) [#16]
Adventure Window is very close to being released! You can see the brand new IDE in action here:

http://dl.dropbox.com/u/79893663/AdventureWindow/Screenshots/AdventureWindowDemo.wmv

Still can't read ini files in monkey, though. I'll provide some code tommorrow...


Midimaster(Posted 2013) [#17]
what's your problem with INI-files?

It is only reading a...
Field Text$=LoadState()

..text, dividing it into lines with...
Lines$[]=Text.Split("~n")

...then scan for the section...
For local Line$ =EachIn Lines
     If Line="[" + section + "]" Then Found=YES

...then divide the lines below into left/right side
If Found=YES
     local Sides$[]=Line.Split("=")

Then scan the left sides...
If Sides[0]="X"

..and the value is here...
X=INT(Sides[1])



I would help you, if you are willing to remove this terrible animation in your signature :-)


Volker(Posted 2013) [#18]
.. remove this terrible animation in your signature :-)

Yes, please.


time-killer-games(Posted 2013) [#19]
Took care of it. Sorry about that...
I need to read strings pointing to image files to load. There doesn't seem to be a built in GetString() in the ini reader. I tried adding one but it always returned an empty string.

Is this anything like what I need to be doing? I get "String can't convert to Int"

Field Text

Method ReadINIString(section,key,value)
Text=LoadString("run.ini") 
Lines[]=Text.Split("~n")
For Local Line$ =Eachin Lines
     If Line="[" + section + "]" Then Found=True
End
If Found=True
     Local Sides$[]=Line.Split("=")
Endif
If Sides[0]=key
value=String(Sides[1])
Endif
Return value
End

Method ReadINIReal(section,key,value)
Text=LoadString("run.ini") 
Lines[]=Text.Split("~n")
For Local Line$ =Eachin Lines
     If Line="[" + section + "]" Then Found=True
End 
If Found=True
     Local Sides$[]=Line.Split("=")
Endif
If Sides[0]=key
value=Float(Sides[1])
Endif
Return value
End



Midimaster(Posted 2013) [#20]
maybe two bugs:
First: define the field Text as Text$
Second: the "run.ini" cannot not be loaded. The LoadString() command only accepts ".txt" files in default.

Try this: Rename the file to "Run.txt". If you develope under HTML5 you could add a line PRINT Text below the LoadString() line.

If not HTML5 you could check with DrawText Text,0,0 in the OnRender()

Strict
Import mojo

Class Game Extends App

	Field Text$
	
	Method OnCreate%()
		SetUpdateRate 60
		Text=LoadString("Run.Txt")
		Print Text
		Return 0
	End	

	Method OnUpdate%()
		If KeyHit(KEY_ESCAPE) Then Error ""
		Return 0
	End	

	Method OnRender%()
		Cls 0,0,0
		DrawText Text,0,0
		Return 0
	End		
End

Function Main%()
	New Game
	Return 0
End



Goodlookinguy(Posted 2013) [#21]
Second: the "run.ini" cannot not be loaded. The LoadString() command only accepts ".txt" files in default.


I completely overlooked the fact that I generally add this in my code when I wrote the above.

#TEXT_FILES+="|*.ini"


I need to read strings pointing to image files to load. There doesn't seem to be a built in GetString() in the ini reader. I tried adding one but it always returned an empty string.


Now that you should be able to read text files, which seems to have been your problem all along, the method from my code for reading strings is just simply "Get"

Update: Here's a working example you can download and run... http://nrgs.org/files/monkey/t4481.zip


time-killer-games(Posted 2013) [#22]
Thanks a ton! Downloading it. Would guys who contributed like credit in my project? I'm more than happy to in fact I insist. it's ironic how I can do it easily in VB6, but have troubles in monkey even though monkey is more easy to understand for most I'd imagine. Anyway string work now I can't thank you guys enough! =]