Jump to content


Photo

Three questions


  • Please log in to reply
9 replies to this topic

#1 simsman2012

simsman2012

    GMC Member

  • New Member
  • 61 posts
  • Version:GM8

Posted 05 July 2012 - 08:26 PM

Concerning the "change sprite" action, does the argument subimage indicate the first subimage that I want to bo shown and if I made it -1, what does it mean?

Also, I want to know how to define a global variable using both "Drag and drop" and coding?

Another thing, I want to know how to make an enemy that follows the player when the player gets to certain distance from it

Thank you and any help will be appreciated!! :smile:
  • 0

#2 Osaifh

Osaifh

    GMC Member

  • New Member
  • 9 posts
  • Version:GM8

Posted 05 July 2012 - 08:31 PM

For the third question, you can use a step action that checks for the variable distance_to_object(Yourobjectname), write a value of distance (i think it's scaled in pixels) and write if you want it equal, bigger than or smaller than
  • 0

#3 TsukaYuriko

TsukaYuriko

    GMC Member

  • GMC Member
  • 510 posts
  • Version:GM:Studio

Posted 05 July 2012 - 08:33 PM

1) It indicates the starting subimage. So if you set it to 0, it will start at the first image (image 0). If you set it to -1, in D&D, the subimage is not changed at all. Keep in mind that setting image_index in GML to -1 will freeze the subimage at the last frame! (If you want a sprite to "just animate" in GML, don't set its image_index, at least not every step)

2) :GM072: Set variable global.something to 1
global.something = 1;
//OR:
globalvar something;
something = 1; //You will have to refer to the variable as "something", not "global.something" this way. Also, local variables called "something" will cause problems, so don't name any other variables the same as your globalvar-defined global variables.

3)
if (instance_exists(obj_player)) {
    if (point_distance(x, y, obj_player.x, obj_player.y) < YOURCERTAINDISTANCEHERE) {
        move_towards_point(obj_player.x, obj_player.y, 5);
        }
    }

Edited by TsukaYuriko, 05 July 2012 - 08:34 PM.

  • 0

#4 simsman2012

simsman2012

    GMC Member

  • New Member
  • 61 posts
  • Version:GM8

Posted 06 July 2012 - 11:31 AM

1) You mean that when I type in the subimage parameter "-1", it will START from the last subimage and WILL NOT go on showing other subimages?

2)When I use Posted Image Set variable global.something to value, how can I use it again

You said before that I must use "something" not "global.something", is this applied to "Drag & Drop" too?
(I mean that in D&D, must I use"global.something" in first defining but when I use it again (in D&D, too) must I use "something"?)

3) (Third answer understood)

I also want to know about DLLs

I am a beginner, so don't get bored :biggrin:

Edited by simsman2012, 06 July 2012 - 11:34 AM.

  • 0

#5 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2239 posts
  • Version:Mac

Posted 06 July 2012 - 12:44 PM

2)When I use Posted Image Set variable global.something to value, how can I use it again

You said before that I must use "something" not "global.something", is this applied to "Drag & Drop" too?
(I mean that in D&D, must I use"global.something" in first defining but when I use it again (in D&D, too) must I use "something"?)

Those last 2 lines of code that TsukaYuriko gave you only apply to GML. If you use Drag and Drop you gotta do it the first way... just put global. in front of the variable's name when you set it and every time that you use it.

I also want to know about DLLs

I am a beginner, so don't get bored :biggrin:

I'd say don't worry about them yet. As far as I know most (if not all) DLLs require you to use code. If you're still learning Drag and Drop then you can't use them anyway.

But for your information, a DLL is just something written in some other language (for example, C++) that allows you to do things in GameMaker that are not built-in features and cannot usually be done in GameMaker alone (with code or otherwise). For example, people who make multiplayer games usually use 39dll. Because the only sort of multiplayer you can do without a DLL is games made with GameMaker's mplay functions, which are pretty limited.
  • 0

#6 ramses12

ramses12

    6

  • GMC Member
  • 5769 posts
  • Version:GM8.1

Posted 06 July 2012 - 01:04 PM

1) You mean that when I type in the subimage parameter "-1", it will START from the last subimage and WILL NOT go on showing other subimages?

Something that does not move does not start either :) It displays the "-1 subimage", which is a simple subimage number, not a "magical one". In this case, it corresponds to the last subimage, because subimage 0 is the first subimage.

2)When I use public/style_emoticons/dark/GM072.gif Set variable global.something to value, how can I use it again

Use the get variable thingie.
Or use code Posted Image

...a DLL is just something written in some other language (for example, C++) that allows you to do things in GameMaker that are not built-in features...

...or that are built-in features and slow enough to cause rage quit.
  • 0

#7 TsukaYuriko

TsukaYuriko

    GMC Member

  • GMC Member
  • 510 posts
  • Version:GM:Studio

Posted 06 July 2012 - 02:57 PM

Answering the stuff that's left to answer...

1) You mean that when I type in the subimage parameter "-1", it will START from the last subimage and WILL NOT go on showing other subimages?

In drag and drop, setting the "subimage" argument of "Change Sprite" to -1 will make the sprite animate with the "speed" you define, even if you put the "Change Sprite" into a step event. It is a magical number in this case, but only in drag and drop.
In GML, using the following code:
sprite_index = sprite0;
image_index = -1;
image_speed = 1;
...which would under normal circumstances be the GML equivalent of "Change Sprite", will make the sprite's subimage freeze at the last subimage and not animate at all. -1 is not a magical number here.

As a general rule: When changing sprites and/or setting its subimage, don't do it every step. (For example, change the sprite to spr_player_left when the player has pressed the left arrow key (= executed once when the player starts walking left), not when the player is holding down the left arrow key (= executed as long as the player is walking left).

I guess the magical -1 in drag and drop was added to make making games easier for the newbies, but in theory, the behavior in GML is the correct one.


Also, an addition on the topic of DLLs: ALL DLLs require you to use GML, since you need to 1) define them so GM recognizes them and 2) call their functions. Neither 1) nor 2) can be done with drag and drop, at least not without additional libraries (not sure whether libraries which allow usage of DLLs in drag and drop even exist). The same goes for extensions - they all require you to use GML to use them. Libraries are an exception here - they offer additional functionality and add corresponding drag and drop icons to the object editor window, but since code is preferred by the majority, don't expect to find libraries which do what you want them to. Extensions or DLLs are just that much more popular. For now, I suggest you focus on learning drag and drop (limited in what can be done), then GML (less limited), and if GML is still not sufficient for your needs, learn how to make GM make use of DLLs (basically unlimited) - this required GML usage, though, so learn that first. As a general rule, unless you can tell me WHAT kind of DLL you need, you don't need one, anyway, so it's best not to worry about them now.
  • 1

#8 simsman2012

simsman2012

    GMC Member

  • New Member
  • 61 posts
  • Version:GM8

Posted 06 July 2012 - 07:32 PM

Concerning the global variable defining, I use "global.<variable name>" in Drag & Drop but I get an error



ERROR in
action number 5
of Draw Event
for object obj_InformationPanel:

Error in expression:global.gold
position 8: Unknown variable gold


Here is my game

Download link: http://www.peejeshar...ies_seeker(TEST).gmk.html

Thank you

Edited by simsman2012, 06 July 2012 - 07:33 PM.

  • 0

#9 TsukaYuriko

TsukaYuriko

    GMC Member

  • GMC Member
  • 510 posts
  • Version:GM:Studio

Posted 06 July 2012 - 07:53 PM

Move the "Set Variable" action which sets global.gold to 0 from obj_InformationPanel's Game Start Event to obj_GameTitle's Game Start Event, or any other object which exists in the first room (obj_InformationPanel doesn't exist there, so its Game Start Event NEVER gets executed at all! Move all the other actions into obj_GameTitle's Game Start Event as well so they actually get executed). For the future, keep in mind to initialize variables which will be needed by the time the gameplay starts before it starts - either at the title screen or even before that. (I tend to make a separate loading room just before the title screen or whatever, where everything gets initialized to ensure it will be loaded or initialized when needed.)
  • 0

#10 simsman2012

simsman2012

    GMC Member

  • New Member
  • 61 posts
  • Version:GM8

Posted 06 July 2012 - 08:26 PM

Thank you guys :smile:
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users