Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

879748 Posts in 33002 Topics- by 24376 Members - Latest Member: xnothegame1

May 24, 2013, 08:28:27 PM
TIGSource ForumsDeveloperTutorialsGame Maker For Beginners: Part II
Pages: 1 2 3 [4] 5 6 7
Print
Author Topic: Game Maker For Beginners: Part II  (Read 56985 times)
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 Email
« 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 Email
« 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 Email
« 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
Matthew Rundle
Level 1
*



View Profile WWW Email
« 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 Email
« 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
Matthew Rundle
Level 1
*



View Profile WWW Email
« 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
xerus
Vice President of Marketing, Romeo Pie Software
Level 10
*


kpulv

Storm+X+MH
View Profile WWW
« 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 Email
« 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 RinkuHero.

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

xerus
Vice President of Marketing, Romeo Pie Software
Level 10
*


kpulv

Storm+X+MH
View Profile WWW
« 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 Email
« 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 Email
« 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
******


xionight@live.com Chimera+Gryphon
View Profile WWW Email
« 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 Email
« 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 7
Print
Jump to:  

Theme orange-lt created by panic