Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1] 2   Go Down

Author Topic: In GML, is there a function to check the current position of an object?  (Read 7556 times)

0 Members and 1 Guest are viewing this topic.
In GML, is there a function to check the current...
« on: January 05, 2009, 04:38:13 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
The title says most of it.  XD

In GML, I'm trying to make it so if a cursor is in a given position, and you press a direction key, it jumps to a designated position.

But where it jumps to needs to be based on the object's current position. I tried having it Check Object and then Jump to Position, but that doesn't work (and I wouldn't expect it to).

So is there a function for "If object is at a given position, perform the next action," or something similar? I'm sure the answer is incredibly obvious, but for some reason it eludes me.
Logged

Mamoruanime

@Mamoruanime
Re: In GML, is there a function to check the cur...
« Reply #1 on: January 05, 2009, 04:39:01 am »
  • ^Not actually me.
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 9786
object.x
object.y

and then your code for it... If this.x == object.x blah blah pseudocode blah blah

O_O


Logged
Re: In GML, is there a function to check the cur...
« Reply #2 on: January 05, 2009, 07:09:56 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
"If object is at a given position, perform the next action,"
if (object.x==x && object.y==y)
{

}

Be more specific mamo O:
Logged
the a o d c
Re: In GML, is there a function to check the cur...
« Reply #3 on: January 05, 2009, 07:30:30 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Perhaps I am thinking about this wrong, but the user who posted this topic might be referring specifically to the drag & drop actions rather than the GML code itself.

Does your code look similar to this?


Otherwise, it would seem odd to me why the built-in function instance_position(x,y,obj) would not work.

It might be depended on where you are checking the code at - in terms of the event.
Logged
Re: In GML, is there a function to check the cur...
« Reply #4 on: January 05, 2009, 09:40:35 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
Actually, 4sword, I tried using both GML and drag-and-drop. But yes, the drag-and-drop version did look like what you said, and then when I opted to script it instead, I couldn't find appropriate functions.

I knew near the start that Check Object wouldn't work, because it checks if there is an object at a position, rather than checking the position of the object...I just tried it because I didn't have another solution. You still gave me some very good advice. I'll try instance_position and then try what mam and AoDC said.

So thanks very much everyone, for your help. It should work now. XD
« Last Edit: January 05, 2009, 09:52:20 am by legendarylugi »
Logged
Re: In GML, is there a function to check the cur...
« Reply #5 on: January 05, 2009, 09:52:23 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
I checked and Check Object translates to position_meeting while instance_position is it's own function. What AoDC said is probably the same thing as what the function I gave does. But honestly, I don't know if what I said will really work.
Logged
Re: In GML, is there a function to check the cur...
« Reply #6 on: January 05, 2009, 10:11:07 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
Okay, so how do I look up an equivalent GML function for a drag-and-drop function?

For instance, the Jump to Position function, how do I find the GML equivalent? Because it seems it's called something else in GML.
« Last Edit: January 05, 2009, 10:12:52 pm by legendarylugi »
Logged
Re: In GML, is there a function to check the cur...
« Reply #7 on: January 05, 2009, 10:22:24 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
There is an old program which does this, it was made by Xception from the GMC. It's in the attachment. Some of the functions may be depreciated as that was from around GM version 5. A lot of it is still relevant.
Logged
Re: In GML, is there a function to check the cur...
« Reply #8 on: January 05, 2009, 10:37:53 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
Wow, that's incredibly useful...and it works! I finally have it working.  XD
Logged

D-Pad

A.K.A. Gyrowolf
Re: In GML, is there a function to check the cur...
« Reply #9 on: January 06, 2009, 06:31:43 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 147
« Last Edit: January 06, 2009, 06:41:44 pm by D-Pad »
Logged
Re: In GML, is there a function to check the cur...
« Reply #10 on: January 06, 2009, 10:48:05 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
Okay, I have another question.

I've actually gotten quite a bit done since I got past that little snag, so I'd like to thank everybody again. But now I have another one.

I'm working on a banking system, and a functional(ish) version is almost complete.

I just need to know how to make it so when you collect rupees (or withdraw/deposit them in the bank), rather than just setting the value of your wallet, for it to gradually add to it (or take from it), like in the games. For instance, when you get a red rupee, rather than just adding 20 to the value, how do I get it to add one at a time?
Logged
Re: In GML, is there a function to check the cur...
« Reply #11 on: January 06, 2009, 10:55:49 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
The first solution that came to my mind and would be easy would be for something in a step event to where you had two variables for rupees - a rupee count and a rupee show. The shown value would be used by the HUD whatever that is showing the amount while the count would be the actual number. In a step event, you could have a condition check whether or not the count matched the shown and then increment/decrement the shown by a fixed number until it matched the actual count.

In a step event, it would look like this:
Code: [Select]
if (rupee_shown > rupee_count)
{
  rupee_shown -= 1;
}
else if (rupee_shown < rupee_count)
{
  rupee_shown += 1;
}

Each step, the value would be augmented until it matched, and the value of 1 I used could be changed to alter the speed of the change.

There might be another way to do it, but meh.

Logged
Re: In GML, is there a function to check the cur...
« Reply #12 on: January 06, 2009, 11:03:15 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
^^^That could work.  XD Whatever the case, I like the idea of rewriting the code to be placed into the step event.

Perhaps make a variable called "worth" that has the value of the given rupee being collided with, and for every step subtract 1 from worth and add 1 to rupees, until worth is at 0? So everytime he collides with a rupee, it sets worth relative to itself, then in the step event starts shaving it back off into the wallet.

Well that sure was simple.  :) I'll test it out right now.

EDIT: If it works, it will simplify the code a lot. Before I had to write a separate script for each rupee, now I can just right one that covers all types.
« Last Edit: January 06, 2009, 11:15:27 pm by legendarylugi »
Logged
Re: In GML, is there a function to check the cur...
« Reply #13 on: January 06, 2009, 11:25:00 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Your idea is also somewhat feasible, but the rupee needs to go away once it is collided with. This usually just involves removing the instance of that rupee. Then, that "shaving" really couldn't happen.

As for how multiple rupee values are to be handled, there are two ways I can think of to do that. One would be to have one rupee object that draws based on its worth, with it's worth immediately going to zero and the incrementation of the rupee count working under what I said to do.

The way it could work for you would be to a base rupee be a parent of all other rupees. In children of the parent, the collision events are inherited, and the only thing that would have to be different in each child would be the sprite of the rupee itself and the rupee worth.
« Last Edit: January 06, 2009, 11:34:17 pm by 4Sword »
Logged
Re: In GML, is there a function to check the cur...
« Reply #14 on: January 06, 2009, 11:43:47 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
^^^Oh, I don't need help with rupee increments, I already had that covered.

I was just saying that before, with the method I was using, I had a seperate "duplicate" script for each rupee, but now I only need one of it.

I guess you're right about "shaving" values into it, since there's no longer an object to run the script. I didn't think of that. (hits self in head). Hmmm, maybe I could put the script under LINK's step event, and set it to "other", so the Rupee is the one affected?
« Last Edit: January 06, 2009, 11:50:58 pm by legendarylugi »
Logged
Re: In GML, is there a function to check the cur...
« Reply #15 on: January 07, 2009, 12:06:23 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
It would probably be more efficient under my method then; the rupee_shown and the rupee_count. And for all intensive purposes, having the rupee objects as one base parent object with children objects would be best. This is because the collision events are inherited and code itself doesn't have to be rewritten.

I should have probably made rupee_count in my example a global variable - i.e. global.rupee_count. This is so interaction with other objects outside of the HUD would be easier. The collision event defined in the parent base object of the rupee would just alter the global.rupee_count variable and then destroy the rupee object.

It's also a bad idea to load code into Link. Other objects harboring the code for things pertinent to them makes more sense then using "other" a lot.
Logged
Re: In GML, is there a function to check the cur...
« Reply #16 on: January 07, 2009, 12:25:26 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
It would probably be more efficient under my method then; the rupee_shown and the rupee_count. And for all intensive purposes, having the rupee objects as one base parent object with children objects would be best. This is because the collision events are inherited and code itself doesn't have to be rewritten.

Alright, I'll do that then.  ;) I'm a newbie, so I have no reason to be stubborn.  :P


It's also a bad idea to load code into Link. Other objects harboring the code for things pertinent to them makes more sense then using "other" a lot.

Yeah, I realize that it would basically mean the game was running unneccessary code at every step and eventually slowing things way down, but I guess it just sounded easier to give it to Link for now. But like I said, I'll try it how you said.
« Last Edit: January 07, 2009, 12:29:39 am by legendarylugi »
Logged
Re: In GML, is there a function to check the cur...
« Reply #17 on: January 07, 2009, 01:55:56 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
Well, I ended up doing it the way I originally said I would, so I guess I'm stubborn after all.  :P

But I tweaked it to a less terrible and noobish form. So it's no longer under Link's step event, it's under the control object that draws the HUD and such.

BTW, I think you slightly misunderstood me about the rupees. I said that in an earlier form it required me to write separate scripts for each rupee, but once I got some inspiration from this thread, I realized how to make one that would work for all of them. So I don't need a parent rupee to get the other rupees to do what I want.

Unless of course you were suggesting the parent rupee for another reason.

« Last Edit: January 07, 2009, 02:06:40 am by legendarylugi »
Logged
Re: In GML, is there a function to check the cur...
« Reply #18 on: January 07, 2009, 02:23:03 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Meh, I would think that the rupees would stay too long your way, when they should go away upon collision.

As for its location outside of Link's step event, that's good that it is in the control object.

I do not know what you mean by scripts; I know what a script is, but the way you are using the word is throwing me off. I get that if you write some code that decrements or whatever, that that code can apply to all rupees. What I do not know if you are doing is if you have multiple rupee objects, does each one have the same lines of code in their collision events?

By having a parent rupee object which defines the collision event for itself, you could have rupee objects of which there would be no code needed or written, other than the value of the different rupee in the create event of each. It's a lot more efficient.

You do know what I mean when I mention parent objects, right?
Logged

Pyrazor

PUMP UP DA JAMS!
Re: In GML, is there a function to check the cur...
« Reply #19 on: January 07, 2009, 03:18:47 am »
  • OH LARD IZ PORKCHOP, BUST OUT DA HAPPY SNACKS
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 191
It sounds like he just has one rupee class that represents all types of rupees by using a variable to distinguish between which type a specific instance represents.  It's actually more efficient than what you suggested 4Sword.

My guess is he's randomly picking which type the instance to be and setting the texture accordingly or he's just doing it in some script that spawns them.
Logged

I C'Z U
Pages: [1] 2   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.061 seconds with 78 queries.

anything