___
Vice President of Marketing, Romeo Pie Software
Level 10
|
|
« Reply #40 on: November 24, 2008, 07:50:33 PM » |
|
I don't think that "other" works in any events outside of collision stuff. : (
|
|
|
Logged
|
|
|
|
ஒழுக்கின்மை (Paul Eres)
|
|
« Reply #41 on: November 28, 2008, 04:42:53 AM » |
|
It doesn't. I assumed he was calling it from a collision event, though. In collision events, other is set to the collided-with instance.
|
|
|
Logged
|
|
|
|
William Broom
|
|
« Reply #42 on: November 28, 2008, 05:25:39 AM » |
|
The only other time I know that other works is inside with statements to refer to the object that 'sent' the statement.
|
|
|
Logged
|
|
|
|
ஒழுக்கின்மை (Paul Eres)
|
|
« Reply #43 on: November 28, 2008, 05:32:04 AM » |
|
You also don't actually need other to refer to it there, you can just use the return value from that collision function. It'd return an instance id, which you can store in a variable and use exactly like you'd use other in a collision event.
|
|
|
Logged
|
|
|
|
KniteBlargh
|
|
« Reply #44 on: December 01, 2008, 08:05:51 AM » |
|
Alright, I've now followed this part of the tutorial, and my little project's looking a bit more game-like. Great work Derek! These tutorials have been the most help to me so far. Oh, and in case you're interested, my project is going to be based around a beetle's life. You're trying to fly to your destination and stuff like that, but there are going to be all these annoying floating seeds in your way among other things that I haven't made yet. Oh, and so far, since shades of vomit haven't been receiving enough love, the entire game is going to be vomit coloured, unless I decide otherwise later on... Blargh...
|
|
|
Logged
|
|
|
|
GregWS
|
|
« Reply #45 on: December 01, 2008, 11:07:44 PM » |
|
Sounds unique! Make sure to create a spam thread in Art and Design once you've got screenshots to display!
|
|
|
Logged
|
|
|
|
Aaron P
|
|
« Reply #46 on: December 03, 2008, 09:28:16 PM » |
|
First, thank you thank you thank you for this. I hadn't even thought of using GML until now, but I see it can be pretty useful. Question. I've followed the tutorial completely, and I've even managed to create a HP system for my ship. But I want to create a grace period for when my ship hits an enemy. I don't know how to tell Game Maker to ignore the code when in grace period.
Code in the ship Create event: grace = 0 graceMax = 20
Code in ship's Step event: //Check if in Grace Period if grace > 0 { grace -=1; }
Code in collision with enemy: //Check if in Grace if (grace > 0) *Here is where I want this code to end if still in grace* else grace = graceMax
Help?
|
|
|
Logged
|
|
|
|
Matt Thorson
|
|
« Reply #47 on: December 03, 2008, 10:03:20 PM » |
|
When the above statement runs, Game Maker stops executing the current script/piece of code.
|
|
|
Logged
|
|
|
|
Aaron P
|
|
« Reply #48 on: December 03, 2008, 10:59:45 PM » |
|
When the above statement runs, Game Maker stops executing the current script/piece of code. Many thanks to you kind sir.
|
|
|
Logged
|
|
|
|
tok
|
|
« Reply #49 on: December 04, 2008, 04:34:19 AM » |
|
I'm having trouble using 'with'. I'll do something like var myx; myx = 0; with some_instance { myx = x; }
But then later, regardless of what some_instance had, myx will still be 0. Is it supposed to do that?
|
|
|
Logged
|
|
|
|
Derek
|
|
« Reply #50 on: December 04, 2008, 04:44:36 AM » |
|
Yes. When you use "with instanceX" anything between the brackets is being called from instanceX, and therefore all the variables are within the scope of instanceX. In your example, "var myx" is being declared outside of that scope. You can't really pass variables back and forth using with. This will do what you're trying to do, though: myx = 0; myx = some_instance.x;
|
|
|
Logged
|
|
|
|
tok
|
|
« Reply #51 on: December 04, 2008, 05:07:59 AM » |
|
Hey, Derek. My trouble is that I don't have a specific instance - I'm trying to find an instance that meets some criteria, and then steal its data. I thought it would work with global variables, like: global.myx = 0; with enemy { if hat = sombrero global.myx = x; } It doesn't, though.
|
|
« Last Edit: December 04, 2008, 05:16:00 AM by tocky »
|
Logged
|
|
|
|
___
Vice President of Marketing, Romeo Pie Software
Level 10
|
|
« Reply #52 on: December 04, 2008, 06:36:16 AM » |
|
What about this. global.self_id = id; with enemy { if (hat == sombrero) (global.self_id).myx = x; }
|
|
|
Logged
|
|
|
|
Matt Thorson
|
|
« Reply #53 on: December 04, 2008, 09:51:02 AM » |
|
What about this. global.self_id = id; with enemy { if (hat == sombrero) (global.self_id).myx = x; }
That seems like a waste of memory, to devote a whole global variable just to one script (the global variable will live on through the entire game!) Try: with enemy { if (hat == sombrero) (other.id).myx = x; }
If I'm not mistaken, other refers to the calling instance when used from a with.
|
|
|
Logged
|
|
|
|
ஒழுக்கின்மை (Paul Eres)
|
|
« Reply #54 on: December 04, 2008, 11:32:11 AM » |
|
Yes, you don't need to use globals, just use 'other' to refer to variables outside of the with() construction. You also don't need to use 'other.id.', 'other.' would work fine alone.
You also don't need those brackets if it's only a single statement. I know it's crazy of me to put everything on a single line, but what I'd do would be:
with (enemy) if (hat == sombrero) other.myx = x;
|
|
|
Logged
|
|
|
|
___
Vice President of Marketing, Romeo Pie Software
Level 10
|
|
« Reply #55 on: December 04, 2008, 11:39:13 AM » |
|
Ah man, other is such a mystery to me. Whenever I think it works, it won't, and vice versa.
|
|
|
Logged
|
|
|
|
Aaron P
|
|
« Reply #56 on: December 04, 2008, 06:22:24 PM » |
|
Ok, I know this is probably basic programming 101, but as previously stated i'm new to Game Maker, let alone programming a game. But I think i'm getting things rolling, just having a problem. //Weapon Menu Controls if (keyboard_check(ord('A'))) { if (weaponDelay > 0) { weaponDelay -= 1; } else { weapon -=1; weaponDelay = weaponDelayMax; } } else { weaponDelay = 0; }
if (keyboard_check(ord('S'))) { if (weaponDelay > 0) { weaponDelay -= 1; } else { weapon +=1; weaponDelay = weaponDelayMax; } } else { weaponDelay = 0; }
In this code, the variable "weapon" refers numerically to the user's currently selected weapon. For example 1=Pistol, 2=Shotgun, 3=Machine Gun, etc... I want the keys A and S to flip between weapons. The problem is since this is inside of the Step event, pressing A or S causes rapid fire flipping of the weapons. So i decided to alleviate the issue by adding a small "delay" between switching weapons whenever the button is held down. However, with the code as written above, the rapid fire switching still occurs. I finally figured out that this is because "weaponDelay = 0" is declared for both keys, effectively making sure that weaponDelay will always = 0. So I tried removing else weaponDelay = 0 from one key, but the result was that whatever key didn't have code still rapid fired when pressed, while the other key worked properly. I can't figure out how to get the keys to play nice. P.S. I'm not sure if i'm bending any forum rules by consistantly asking questions within this topic, or if I should be making my own topic. If I am breaking a rule or generally annoying people, I apologize. P.S. Part 2: If anyone would be willing to answer "every now and again" questions about Game Maker via AIM so that I don't have to clutter this forum, PM me please! Thanks.
|
|
|
Logged
|
|
|
|
Derek
|
|
« Reply #57 on: December 04, 2008, 07:03:02 PM » |
|
No, that's exactly what this forum is for! Keep asking them questions. Learning how to program games is hard enough without people trying to make you feel dumb... and besides, if you don't ask on the forum, then other people with the same question won't get their answer. Anyway, instead of adding a delay, what you probably want to do is check if the key is first pressed down: AKey = false; AKeyPressed = false;
AKeyReleased = false; if (AKey) { AKey = keyboard_check(ord('A')); AKeyPressed = false; if (AKey) { AKeyReleased = true; } } else { AKey = keyboard_check(ord('A')); if (AKey) { AKeyPressed = true; } }
What it's doing is checking if the key is held down, and if it is, it figures out whether it's for the first time. If it's not being held down, it figures out whether it was held down in the last step. So now you can check if the key is being held down (AKey), first pressed (AKeyPressed), and released (AKeyReleased). It's kind of a pain, and requires 3 variables, so honestly I'd just use Game Maker's built-in Key Press and Key Release events for what you're doing. Unless you really need that other data. weapon -= 1; if (weapon < 0) weapon = weaponMax;
weapon += 1; if (weapon > weaponMax) weapon = 0;
I added some code that will make it cycle to the beginning and end if you go out of bounds.
|
|
|
Logged
|
|
|
|
Xion
|
|
« Reply #58 on: December 04, 2008, 07:33:03 PM » |
|
couldn't you just use keyboard_check_pressed() instead of keyboard_check()? It returns whether the key was just pressed down as opposed to having been held, right?
|
|
|
Logged
|
|
|
|
Derek
|
|
« Reply #59 on: December 04, 2008, 07:47:29 PM » |
|
Yeah, that works, too. See, we all learn! :D
I should have guessed - I think for every event there's a corresponding GML function.
|
|
|
Logged
|
|
|
|
|