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 7616 times)

0 Members and 1 Guest are viewing this topic.
Re: In GML, is there a function to check the cur...
« Reply #20 on: January 07, 2009, 03:37:16 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
I mentioned previously in this topic having a single rupee object that based what type of rupee it was on by its "worth" and then having its sprite be determined in the draw event. However, if you decrement the "worth" of the rupee with what I just mentioned, the rupee will change colors, and this is not what you would want. You could make it invisible before it destroys itself, but then it would still be running collision events; which might make it look like the rupee doesn't stay that long by increasing the number of collisions as the rupee itself isn't solid.

Another problem with that is that you have to assign a value to a rupee once it is created which involves more code. If this were C++, there would be an argument to the constructor to do this, but in Game Maker, you would have to set the code immediately after creating the rupee.

It's a lot less work to have a parent rupee as then all children are essentially empty except for the field where the parent rupee is declared as the child's parent. And really, my original way of doing it with a rupee_count/rupee_shown with that would be the best solution in my opinion. And this isn't really about the rupee spawning so much as it is about the rupee incrementation/decrementation to the number of rupees you have.

Perhaps there is something in what you are saying that I am missing.

Edit:

I thought about it a little more. If you had one rupee represent all rupee worths and you did not decrement from the worth of rupee incrementally to add to the rupee count, then that would work. Rupees are mostly generated due to the death or destruction of things, thus the rupee is created after before that death and destruction line in the code. Sometimes, the value assigned is not always the same for the same thing destroyed (like getting one or a five value rupee) and that is determined through probability.

Meh, the way I see it, the parent-child relationship avoids the decision statement in the draw event and saves a line of code, but meh.
« Last Edit: January 07, 2009, 04:41:03 am by 4Sword »
Logged
Re: In GML, is there a function to check the cur...
« Reply #21 on: January 07, 2009, 06:38:11 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
I guess we have somewhat misunderstood eachother.    :P

Okay, so to clarify what I'm doing, here's what I mean.

Okay, so right now I have a separate object for each rupee-type (for now, but that's subject to change), but the only thing they do is upon collision, set "worth" relative to ____ (whatever the rupee is), and then run "collect_script_B", which basically just tells it that if your wallet can hold at least part of the value of the rupee, destroy it, otherwise don't collect it.

The HUD object runs "collect_script_A" in the step event, which just tells it to add the rupees one at a time, subtract from worth one at a time, and play the rupee_get sound, until worth equals zero. Or, if your wallet is full, set worth to zero. So far it's working just fine.

So I don't get what you mean about the object not being immediately destroyed after collision. It's destroyed instantly.
Logged
Re: In GML, is there a function to check the cur...
« Reply #22 on: January 07, 2009, 10:21:54 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Can I see your GMK file?
Logged
Re: In GML, is there a function to check the cur...
« Reply #23 on: January 07, 2009, 11:12:12 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
^^^I would love to show you my .gmk, but it's a little messy right now. I need to clean it up a bit first.  :P

Anyways, I think we're getting bogged down on what ultimately, are miniscule differences of approach. What you would have done, and what I did, are all but identical, using the difference between 2 variables (one for the rupees and one extra variable) to mark how many rupees to add, one per step, with each type of rupee it's own object, but essentially "empty" except for marking the value of the rupee (and in my case running the script that would be run by the parent in yours).

The only difference, the ONLY difference that I see, is that your extra variable was the current rupees plus the rupees gotten, so adding to the rupees to your wallet until they reached that point, whereas my extra variable was just the value of the rupee you collided with, added one at a time to your wallet and removed one at a time for this second variable. Basically the same thing.

As for the rupees, like you I have multiple rupee objects, the only difference was that I didn't create a parent object for them, since the collision event, the only event they had, and the only thing that would have been in the parent in the first place, was different for each of them (added a different value to the worth variable), so a parent served no purpose the way I did it.

Like I said, the differences are a lot smaller than they're being made out to be.

EDIT: But now that I think about it, your way would be a bit simpler, because rather than having to change the values of 2 variables to add to the rupees, your way would only have to change one. So I think, yes, I will change it.  ;)
« Last Edit: January 07, 2009, 11:19:34 pm by legendarylugi »
Logged
Re: In GML, is there a function to check the cur...
« Reply #24 on: January 07, 2009, 11:46:43 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
lol, yeah my code gets messy a lot too; I also have the tendency to stop working on code if I dislike the way it looks in terms of variable names, structure, etc.

But as for the rupees, in Zelda games, there are a few values for the rupees themselves; a one, five, ten, twenty, etc. Saying you had just those first four, that would mean that you have four rupees, all with collision event code. If the collision event involves a function call, such as there is a script that is executed, then at least then the code would not be written more than once. While it isn't much to say, the purpose of most scripts is similar code with different passed in arguments.

If you had a parent rupee and then children rupees, it would be different. The parent object would define the variable for the rupee's worth as well as it would have the collision event defined. The children rupees would have no code at all other than an event_inherited() call in the creation event and a statement setting the worth of the rupee to a value.

So meh, instead of having four rupees all with collision code of their own or having four rupees with a function call to a script that had no arguments, you would have a parent rupee that defines everything, and smaller child rupee objects that save space by needing less code themselves. Meh, it's not the only way to do it, but for me, it would be the better practice. It probably sounds a little miniscule, but it adds up with the more similar objects you have.
Logged
Re: In GML, is there a function to check the cur...
« Reply #25 on: January 07, 2009, 11:53:47 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
^^^Ah, I see, that makes sense. I think I will do that, create a parent object for them. But I think I'll keep the rest as it is, using a worth variable to set the number of rupees to add.

BTW, how do I upload a .gmk to my posts?

Basically, I cleaned out the file, removed any unneccessary junk, and then took out everything to do with the banking part (withdrawing, depositing), keeping in only Link and the ability to get rupees...since I don't want to upload the banking part till it's finished.

Lol, now that it's all cleaned up, I realize that outside of the bank, when it comes to just collecting rupees, I've coded practically nothing.  :P
« Last Edit: January 07, 2009, 11:57:51 pm by legendarylugi »
Logged
Re: In GML, is there a function to check the cur...
« Reply #26 on: January 07, 2009, 11:57:15 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
I usually just create a .zip or a .rar file on my computer, open in up, add the GMK into that, and then go to the forum, go to make a post, click additional options before posting, and then attach the .zip or the .rar file.
Logged
Re: In GML, is there a function to check the cur...
« Reply #27 on: January 08, 2009, 12:02:37 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
Okay, I'll be right back with it.  ;)

EDIT: Okay, it's just a very, very basic version. Press the F key to upgrade your wallet, press the arrow keys to move "Link" around (yes, his movement is preschooler level), and collide with rupees to collect them. Make sure you have the sound turned on, because an important part is the collect_snd.

I realize that I made a few of the variables global when they probably didn't need to be, but I just did that for now so I didn't have to think about it as much.
« Last Edit: January 08, 2009, 12:16:07 am by legendarylugi »
Logged
Re: In GML, is there a function to check the cur...
« Reply #28 on: January 08, 2009, 01:20:23 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Here is a file with some things changed. Namely, I implemented the parent rupee object with its children, changed the resource names to the more appropriate Hungarian prefixes, implemented the rupee variables, altered up some of the Link code to make it more efficient, etc. I realize that you were using drag & drop a bit with scripts, but yeah, using the execute code found under the control tab lets you run your own code. Sometimes drag and drop does more than it needs to; e.g. setting the sprite, in your example, you just needed to change the index and you didn't have to redeclare what the sprite was.

I also put the rupee_shown/global.rupee_count check in the draw event just for simplicity. Mostly the draw event should just draw and not run code, but it still happens before the number is drawn so it is alright.

A few key things beyond all that, the global.rupee_max is altered when you upgrade you wallet. In the collision event for objRupeeParent, the global.rupee_count is altered by the smaller of the two values - them being the global.rupee_max or the global.rupee_count + worth. Basically, if the increment to the global.rupee_count is greater than the global.rupee_max, the global.rupee_count will equal just the global.rupee_max. This prevents you from exceeding the max if you are at it, or if you are like 5 under it and get a 20, it sets it to the max then. I actually learned this way of doing it from someone else.

But yeah, it's in the attachment. Attachment removed and reuploaded in next post.
« Last Edit: January 08, 2009, 03:12:19 am by 4Sword »
Logged
Re: In GML, is there a function to check the cur...
« Reply #29 on: January 08, 2009, 03:03:35 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
Lol, don't worry about fixing "Link" 's movement, he was only in there to have something to collide with the rupees, nothing more than that...if it were a walking engine I would have put much more thought into him.


Anyways, I can't really check what you did, since I don't have a .rar opener on my computer.  :-\ Could you maybe upload it as a .zip?

Logged
Re: In GML, is there a function to check the cur...
« Reply #30 on: January 08, 2009, 03:11:17 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Meh, it seems the WinRAR made it into a rar, when other archives I made using WinRAR were compatible zip. Anyway, I think I might be able to just upload it without that, lol, silly me.
Logged
Re: In GML, is there a function to check the cur...
« Reply #31 on: January 09, 2009, 01:15:29 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
I really like your version, it does seem "smaller", more efficient. The only problem I have with it is the sndCollect no longer loops appropriately...that and the fact that I don't know what certain things, like cases are...but I can sort of infer what they are from the context.
Logged
Re: In GML, is there a function to check the cur...
« Reply #32 on: January 09, 2009, 01:24:12 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
That "problem" is easy to fix. Just remove the code about playing the rupee collect sound from the rupee collision and put it into the code inside the objControl for when the rupee_shown is altered positively.

And cases, or select-case statements are a quick way of doing if-else. For example:
Code: [Select]
  switch (wallet)
  {
    case 2: global.rupee_max = 200; break;
    case 3: global.rupee_max = 500; break;
    case 4: global.rupee_max = 500000; break;
  }

is equivalent to:
Code: [Select]
if (wallet == 2)
{
  global.rupee_max = 200;
}
else if (wallet == 3)
{
  global.rupee_max = 500;
}
else if (wallet == 4)
{
  global.rupee_max = 500000;
}
Logged
Re: In GML, is there a function to check the cur...
« Reply #33 on: January 09, 2009, 01:40:45 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
^^^Thank you very much for showing me that.  XD

EDIT: BTW, I realize that the looping of the rupee sound is actually kind of annoying right now, so I will try to fix that.
« Last Edit: January 09, 2009, 02:12:01 am by legendarylugi »
Logged
Pages: 1 [2]   Go Up

 


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



Page created in 0.06 seconds with 61 queries.

anything