Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411414 Posts in 69360 Topics- by 58415 Members - Latest Member: sophi_26

April 16, 2024, 12:55:52 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Game Maker For Beginners: Part II
Pages: 1 2 [3] 4 5 6
Print
Author Topic: Game Maker For Beginners: Part II  (Read 136386 times)
___
Vice President of Marketing, Romeo Pie Software
Level 10
*


View Profile
« 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)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« 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
Level 10
*****


formerly chutup


View Profile
« 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)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« 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
Level 4
****


Blargh...


View Profile WWW
« 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. Undecided 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
Level 10
*****


a module, repeatable in any direction and rotation


View Profile
« 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!  Kiss
Logged
Aaron P
Level 0
***

!


View Profile
« 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
Level 7
**

c'est la vie


View Profile WWW
« Reply #47 on: December 03, 2008, 10:03:20 PM »

Code:
exit;

When the above statement runs, Game Maker stops executing the current script/piece of code.
Logged

Aaron P
Level 0
***

!


View Profile
« Reply #48 on: December 03, 2008, 10:59:45 PM »

Code:
exit;

When the above statement runs, Game Maker stops executing the current script/piece of code.

Many thanks to you kind sir.  Gentleman
Logged
tok
Level 4
****


View Profile
« Reply #49 on: December 04, 2008, 04:34:19 AM »

I'm having trouble using 'with'.

I'll do something like

Code:
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
Bastich
Administrator
Level 10
******



View Profile WWW
« 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:

Code:
myx = 0;
myx = some_instance.x;
Logged
tok
Level 4
****


View Profile
« 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:
Code:
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
*


View Profile
« Reply #52 on: December 04, 2008, 06:36:16 AM »

What about this.
Code:
global.self_id = id;
with enemy {
    if (hat == sombrero)
        (global.self_id).myx = x;
}
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #53 on: December 04, 2008, 09:51:02 AM »

What about this.
Code:
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:

Code:
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)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« 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
*


View Profile
« 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
Level 0
***

!


View Profile
« 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.

Code:
//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.  Cry

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
Bastich
Administrator
Level 10
******



View Profile WWW
« 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. Wink

Anyway, instead of adding a delay, what you probably want to do is check if the key is first pressed down:

Code: (Create Event)
AKey = false;
AKeyPressed = false;

Code: (Step Event)
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.

Code: (Press <A> Event)
weapon -= 1;
if (weapon < 0) weapon = weaponMax;

Code: (Press <S> Event)
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
Pixelhead
Level 10
******



View Profile WWW
« 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
Bastich
Administrator
Level 10
******



View Profile WWW
« 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
Pages: 1 2 [3] 4 5 6
Print
Jump to:  

Theme orange-lt created by panic