If-Then Statements
Monkey Forums/Monkey Programming/If-Then Statements
| ||
Here is my current code:Import mojo Import monkey Import diddy Import "C:\Users\Joseph\Documents\SleepingDisorder\animation001_strip24.png" Import "C:\Users\Joseph\Documents\SleepingDisorder\cursor01.png" Import "C:\Users\Joseph\Documents\SleepingDisorder\cursor02.png" Global anim_cnt:Int = 0 Global animation:Image Global Cursor01:Image Global Cursor02:Image Global Click0001:Bool = False Global SetCursor0001:Bool = False Global myGame:MyGame '************************************************************************* ' THIS IS THE MAIN CLASS '************************** Function Main:Int() myGame = New MyGame Return 0 End Function '************************** Class MyGame Extends App Method OnCreate:Int() HideMouse() SetUpdateRate 30 Cursor01 = LoadImage("cursor01.png") Cursor01 = LoadImage("cursor02.png") animation = LoadImage("animation001_strip24.png", 640, 480, 24) 'ANIMATION STRIP IS 64X64 WITH 16 IMAGES IN IT Return 0 End Method OnLoading:Int() Return 0 End Method OnUpdate:Int() Return 0 End Method OnRender:Int() Cls 0, 0, 0 DrawImage(animation, 0, 0, anim_cnt) If Click0001=True Then anim_cnt += 1 If anim_cnt > 23 anim_cnt = 23 If MouseX<100 And MouseY<480 Then SetCursor0001=True If SetCursor0001=True Then DrawImage(Cursor02,MouseX-32,MouseY-32) If SetCursor0001=False Then DrawImage(Cursor01,MouseX-32,MouseY-32) Return 0 End End I'm making a pre-rendered 3d point-and-click puzzle adventure game. Here's what I'd linke to know: How to use If-Then statements, I used to make games with GamaMaker but decided to move on into using Monkey. This is what I'm us to doing with If-Then statements: if (<variable/function>==<returnvalue>) {/*Enter more code here*/} But that isn't how Monkey works, you can't use "{}" Every time I try to use an If-Then statement it returns this error: Monkey Runtime Error : TypeError: Error #1009 ?<?> I'm not really sure what I'm doing wrong here, I want the cursor image to change when its x/y positions are less than 100/480 and change back to the default cursor when the mouse isn't hovering over that area. Is there a better tutorial on how to use the If-Then statement? The Docs aren't really helping me. Thanks! TKG |
| ||
[monkeycode] If var = 1 then 'do something in here. End if If(var = 1) or (var = 2) 'do something End if if(var = 1) 'var = 1 else 'var does not = 1 EndIf if(var = 1) And (var = 1) 'var is 1 DUH! Print "Var = 1" ElseIf(var = 2) Print "Var = 2" ElseIf(var = 3) Print "Var = 3" EndIf [/monkeycode] think this is what you were asking sorry just glanced over your post cos im in a rush.. |
| ||
I should say that I like to nest everything i find it makes things so much simpler to read, at least it does for me. |
| ||
most blocks start with a statement and end with the "End". For the If block the "End" can be interchanged with "EndIf". If statement 'block of code End you can make do with out the "End/EndIf" for the "If" command but the block has to be done in the same line If <comparison> Then <block of code> |
| ||
For example your little bit of code, when done with a nested if then else. [monkeycode] If SetCursor0001=True DrawImage(Cursor02,MouseX-32,MouseY-32) Else DrawImage(Cursor01,MouseX-32,MouseY-32) EndIF [/monkeycode] |
| ||
And if you want you can just use "End": [monkeycode]If x = y 'Do something End[/monkeycode] BTW Why are you importing your images at the top of your file? |
| ||
lol therevills, I was wondering the same. |
| ||
Maybe he doesn't want to have to keep copying files from his asset library to the data folder every time he changes them or has to clean his monkey project. |
| ||
Also you dont have to "import monkey"... |
| ||
I imported the images because that is the only way I can to get them in the data folder, if I just drag and drop the images from where ever to the data folder every time I build the files in the data folder seem to get deleted. Thanks everyone. Got it working. |
| ||
You need to set up your project as follows:\projectFolder \project.data \animation001_strip24.png \cursor01.png \cursor02.png \project.monkey I find it a bit strange and annoying that we have to create the data folder with the prefix of the project name... Check out this tutorial: http://blitz-wiki.appspot.com/Drawing_with_Images |
| ||
therevills: nice to have that tutorial there, I wonder if there's more? According to the wiki, no page links to it, so it's an orphan? Without a search option or a proper index, there'd be no way to find pages like this! (edit: found the index. That darn wiki still needs a search/goto option..) |
| ||
I found that tutorial in the Tutorial section on the left hand side of the wiki ;) http://blitz-wiki.appspot.com/Tutorials |