View Full Version : Game Maker Help Thread (Post your Qs here!)
Kensei
10-01-2009, 12:29 AM
Could you not use a normal sprite/object? I know it is a very simple solution and there is likely a better thing but that is how I would do it :p
Create a cone like shape as a sprite and then if an object collides with the flashlight object, it becomes visible - hell you could even make a collision circle, so if an object falls within a radius of the light, it is made visible
The Dash
10-01-2009, 10:34 AM
Could you not use a normal sprite/object? I know it is a very simple solution and there is likely a better thing but that is how I would do it :p
Create a cone like shape as a sprite and then if an object collides with the flashlight object, it becomes visible - hell you could even make a collision circle, so if an object falls within a radius of the light, it is made visible
i thought of doing that, but if the object touched the side of the cone, its whole body would be shown =P
The best solution i have at the moment is a giant sprite that covers everything with a slice left open, but im hoping for a better solution =P
dislekcia
10-01-2009, 12:30 PM
i thought of doing that, but if the object touched the side of the cone, its whole body would be shown =P
The best solution i have at the moment is a giant sprite that covers everything with a slice left open, but im hoping for a better solution =P
That's pretty much what I'd suggest as well, it's also the basis for a lot of "advanced lighting engines" in GM: Create a surface the size of the screen, fill it with black and then remove the alpha of the surface wherever you have light sources. I couldn't find you a link last night, but google a dude called GearGod and look for his GM lighting system.
Anyone have a link to that or the other one that did the rounds? Fengol?
Squid
10-01-2009, 02:33 PM
Anyone have a link to that or the other one that did the rounds? Fengol?
http://www.messy-mind.net/game-maker/luminaire/
CiNiMoDZA
15-01-2009, 09:13 PM
Hey, can someone please help :P Im making a game where you constantly scrolling around the screen with you mouse, like in an RTS, but how can I draw a value in the corner of the screen and it stays there?!? Even when Im scrolling around?!
Elyaradine
15-01-2009, 09:36 PM
I'm not certain, but I think you can try using the draw_text function.
SkinkLizzard
15-01-2009, 09:36 PM
thats relatively simple, if you are using views to move around:
view_xview and view_yview are the x and y coords of the top left corner of the view in the world,
and view_hview and view_wview are the height and width of the view in the world.
using these values you can have an object draw text, for example
draw_text(view_xview+10,view_yview+90,string(somev alue)),
this should draw the value stored in somevalue 10 pixels from the left of the screen and 90 pixels from the top.
dislekcia
15-01-2009, 10:06 PM
Hey, can someone please help :P Im making a game where you constantly scrolling around the screen with you mouse, like in an RTS, but how can I draw a value in the corner of the screen and it stays there?!? Even when Im scrolling around?!
Two methods:
Either reposition the object that draws the value every frame according to the view's x and y locations (view_x[number], view_y[number] - I think).
Or have two views active, put one in a specific area where you put all your interface objects and make sure it doesn't have a background. Then it'll draw the "HUD" over the view underneath it, which is the scrolling one.
CiNiMoDZA
15-01-2009, 10:06 PM
Ahh, thank you mr lizzard sir, most helpful!! and mr dislekia :D your message popped up after I posted!!
CiNiMoDZA
16-01-2009, 12:49 PM
Ok, Ive run into a problem again! Ive made a HUD object, and in its step event I have the following:
x = view_xview + 512
y = view_yview + 708
which positions it perfectly where I want it. However, when I move the camera, it lags behind, and when I stop it goes to where it should be?!? How can I fix this???
Ok, Ive run into a problem again! Ive made a HUD object, and in its step event I have the following:
x = view_xview + 512
y = view_yview + 708
which positions it perfectly where I want it. However, when I move the camera, it lags behind, and when I stop it goes to where it should be?!? How can I fix this???
Put this in your draw code and it wont lag. I had this problem with Pea Adventures as the view only updates after the step events end just before the draw event (or something like that)
SkinkLizzard
16-01-2009, 04:12 PM
the hud object doesnt actually have to move
just manually draw the hud in the right place,
you'd have to do this anyway if you put the moving code in the draw event as that overrides the objects default draw.
If you're still battling I can whip up a quick hud example for you if you'd like?
CiNiMoDZA
16-01-2009, 06:33 PM
Please, an example would be nice!!! The draw event thing isnt working?!? If I put it in the draw event it disappears!
SkinkLizzard
16-01-2009, 11:28 PM
A small HUD example (http://www.mediafire.com/?jmzgzdyhhmn)
hope it helps
CiNiMoDZA
17-01-2009, 12:02 AM
Thankyou kind sir, works perfectly... :D
Obi Two Kenobi
18-01-2009, 02:47 PM
I am in the process of creating a bulldozer-type game
(for you who don't know what that is, in the game you control a bulldozer and you must push a certain number of rocks onto targets to progress to the next level)
In the game I have all the movement actions done, but I've been wondering for a while how I make it so that when ALL the rocks are in position, THEN the game goes to the next room.
CiNiMoDZA
18-01-2009, 03:46 PM
Not the smartest guy here, but maybe create a variable called rocks, then give it the value of the amount of rocks you need before you go on to the next level, so, lets say 5. Now, assuming you're using game maker, in the create event,
CODE:
rocks = 5
Then when you place a rock on a target, tell it to minus on from rocks! Then, in a step event, when it reaches 0, go to next level!! Crappy explanation, but it'll work!!
My turn, how do I make a menu disapear by clicking in the background?!?
Obi Two Kenobi
18-01-2009, 04:01 PM
Awesome thanks!
Insomniac
18-01-2009, 04:47 PM
Not the smartest guy here, but maybe create a variable called rocks, then give it the value of the amount of rocks you need before you go on to the next level, so, lets say 5. Now, assuming you're using game maker, in the create event,
CODE:
rocks = 5
Then when you place a rock on a target, tell it to minus on from rocks! Then, in a step event, when it reaches 0, go to next level!! Crappy explanation, but it'll work!!
My turn, how do I make a menu disapear by clicking in the background?!?
That's a good, potential solution but don't check for it constantly in the step event.
Instead whenever you subtract from rocks check if it's equal to 0 and then change room.
SkinkLizzard
18-01-2009, 05:00 PM
cinimod, a rather simple solution I learned from trooj back with comp 10
set the mask_index for the menu object and all its buttons to an empty sprite
and set its depth to a suitably high number so that its behind everything else in the game.
do the reverse when you need to get it back...
use the global mouse left relesed event, in the event check for a colission_point at mouse_x and mouse_y if collision function returns something other than the menu do the above stuff.
I'm not sure how understandable my explanation is..
The Dash
18-01-2009, 05:04 PM
cinimod, a rather simple solution I learned from trooj back with comp 10
set the mask_index for the menu object and all its buttons to an empty sprite
and set its depth to a suitably high number so that its behind everything else in the game.
do the reverse when you need to get it back...
use the global mouse left relesed event, in the event check for a colission_point at mouse_x and mouse_y if collision function returns something other than the menu do the above stuff.
I'm not sure how understandable my explanation is..
could you not also use
instance_activate_object(obj)
instance_deactivate_object(obj)
?
SkinkLizzard
18-01-2009, 05:36 PM
yea you could but you'd have to do the activating and deactivating from a seperate object you couldn't do it from the menu itself.
The Dash
18-01-2009, 08:18 PM
yea you could but you'd have to do the activating and deactivating from a seperate object you couldn't do it from the menu itself.
the object itself only needs two lines of code
and the menu could deactivate itself, but it really comes down to how the menu works
CiNiMoDZA
21-01-2009, 07:08 PM
Is there a way to make a menu pop up and freeze all the other things happening in the background?!?
SkinkLizzard
21-01-2009, 08:03 PM
yes but the only way I know is to code it into every action in the game
so that it checks a global variable global.menu before doing anything
CiNiMoDZA
21-01-2009, 09:59 PM
Ja, I know that way...I was just hoping there was an easier way :'(
dislekcia
21-01-2009, 10:17 PM
Ja, I know that way...I was just hoping there was an easier way :'(
You could run your own loop within the game that checks input, moves stuff around on the menu and redraws the screen. There are functions for all of that in GML. That way your menu can pop up and "stop" the game... It is a little complex to pull off tho.
CiNiMoDZA
22-01-2009, 11:09 AM
If you have any free time and would maybe like to demonstrate :P It cant hurt to try?!?
Kensei
22-01-2009, 01:29 PM
once you figure out what needs to be done in the loop its easy :p
Then you could just have:
if(isPlaying == true)
{
<do stuff>
}
then if you press the 'P' button it sets the isPlaying value to either true or false.
So, what you need to do, is figure out how to take over the controls of the objects moving around the screen, the counter and whatever else you need.
Here's an idea, run your game as it stands now, and write down all the things that change over time - such as moving pieces and money counters etc.
Good luck
Also check the actual GM forums, perhaps someone has tried this stuff before?
I can think of how to make a message popup, but not a menu :(
Bonezmann
22-01-2009, 07:30 PM
Whenever I need to do that I just replace everything with fakes :D For Instance:
(I hope I understand what's going on here)
In a game I'm busy devving now, you get a message at the beginning of some levels. To continue you must press enter. I did it like this:
I have two objects you can move on the screen, so instead of placing the actual objects, I made two fake ones and placed them at the starting place.
In my message box's KeyRelease ENTER event I let it delete the block and change the two objects into the real ones.
What I'd do is, create an object called menu_check. In the step event I'd check to see if the menu exists, for this I'd use the check number of objects icon. The order would be like this: (This isn't actual code, I use the icons)
If menu instance = 1
then set <object name here> speed to 0
If menu instance = 1
then set <next object name here> speed to 0
That would be another of Bonezmann's dud workarounds ;)
The Dash
22-01-2009, 08:17 PM
Hmmm, would using a master parent with a Exit Event for everything also work? then everything has this as its parent and you only have to check if the menu's active with this one object?
dislekcia
22-01-2009, 10:10 PM
Hmmm, would using a master parent with a Exit Event for everything also work? then everything has this as its parent and you only have to check if the menu's active with this one object?
Yes, using inheritance you could create a PauseableObject parent which exited from various events if a global.paused variable was true.
You would have to do your object movement and positioning in script though instead of using the built-in movement systems. But it's probably one of the easier ways to pause an entire game when you don't have access to a complete game-loop.
...
I'm pretty sure that this type of gameplay pausing question has been discussed to death on the GMC forums. I'll see if I can find some relevant links ;)
CiNiMoDZA
24-01-2009, 11:22 AM
At the moment Im doing something like that, but, and Im asking this ou of pure laziness :P what happens when you deactivate an object in GM, does it stop it completely, or what?!?
The Dash
24-01-2009, 07:22 PM
At the moment Im doing something like that, but, and Im asking this ou of pure laziness :P what happens when you deactivate an object in GM, does it stop it completely, or what?!?
I dont technically know what happens, but think of it as deleting the object, it no longer exists and doesn't generate any events
dislekcia
25-01-2009, 12:28 PM
At the moment Im doing something like that, but, and Im asking this ou of pure laziness :P what happens when you deactivate an object in GM, does it stop it completely, or what?!?
The deactivated object is removed from all the processing queues in GM, so it's no longer drawn, doesn't receive keyboard or mouse events, doesn't have a Step event, etc. It's pretty much rendered invisible to GM in general, that's why you have to keep a reference to the deactivated object so that you can re-activate it again.
If you don't do that, you're pretty much just manually creating a memory leak ;)
SkinkLizzard
26-01-2009, 05:56 PM
Hey I'm having a problem with gm7's file_find_first() function
i've given it the mask: working_directory+'\Sprites\*.png'
but despite the directory existing and containing png files the file_find_first fails to find any of the .png's
unless they're in working_directory
edit: stupidest bug ever, seems gm didn't like the single ' marks for the mask...
dislekcia
26-01-2009, 06:05 PM
Hey I'm having a problem with gm7's file_find_first() function
i've given it the mask: working_directory+'\Sprites\*.png'
but despite the directory existing and containing png files the file_find_first fails to find any of the .png's
unless they're in working_directory
Which masks have you tried? Have you left out the initial backslash? Tried forward slashes instead?
What about GM having functions to change the working directory? You could change it, find the pngs and change it back, maybe?
SkinkLizzard
26-01-2009, 06:15 PM
yea I'd tried all of that, hadn't thought of changing the working directory and then changing it back.
I got it working, edited my post :)
thanks anyway
dislekcia
27-01-2009, 12:18 AM
yea I'd tried all of that, hadn't thought of changing the working directory and then changing it back.
I got it working, edited my post :)
thanks anyway
edit: stupidest bug ever, seems gm didn't like the single ' marks for the mask...
Many weakly-typed languages don't differentiate between ' and " when defining strings. GM acts like a weakly-typed language, but it's actually strongly-typed (just uses dynamic assignment for ease of use): single quotes are taken to mean character input, while double quotes are reserved for strings ;)
Jeronkey
03-02-2009, 05:33 PM
Hmmmmmmmmm.... any suggestions on a good way to tackle path-finding?
I know of mp_potential_path and its kin, but the main problem with that is it tends to move diagonally, and I'm wanting in straight lines. Any tips?
Weird text example... I'm wanting the object to move from + to X like so.
+
|
|
|
|
|________X
I hope someone understood that.. :P
Chippit
03-02-2009, 05:53 PM
There are numerous ways to do this, but it's often not as simple as it initially sounds. Nandrew outlined a fairly simple grid-based pathfinding algorithm that will return results like this in an old Dev.Mag issue. You can get that here (http://www.devmag.org.za/viewissue.php?id=13). It's efficient for many applications, and should do what you want. See if that sets you on the right track.
If you don't have obstacles, you can simply compare x and y-values and change them one at a time. That'll get you movement like this too, but wouldn't check for obstacles in the way.
Jeronkey
04-02-2009, 12:58 PM
Chippit <3
Thanks a ton, those list functions in GM are rather useful, never knew about them before. :O
Oh, and kudos to Nandrew for writing the article in the first place. :D
Gazza_N
04-02-2009, 01:04 PM
Pssssst... You are aware that GM does A* pathfinding right out of the box, right? I've used it myself in past projects. ;)
Check it out in the GM help (search for A*). It's a bit more involved than you may be used to, but it works like a dream.
Chippit
04-02-2009, 01:21 PM
Pssssst... You are aware that GM does A* pathfinding right out of the box, right? I've used it myself in past projects. ;)
Check it out in the GM help (search for A*). It's a bit more involved than you may be used to, but it works like a dream.
OR you can do this. I was just taking the opportunity to shamelessly plug my magazine, that's all...
>_>
<_<
(You ruined everything, Gazza!)
HolyMackerel
06-02-2009, 01:37 PM
I am quite new at game maker's coding and scripting. So this might sound a stupid question.
Is it possible to use just code to create a character's basic movement (Up, down, left, right) without using the drag and drop function?
SkinkLizzard
06-02-2009, 03:10 PM
yes its possible to use code to move objects around, in fact its relatively easy even to do keyboard input yourself, but I wouldn't advise that bit of redundancy unless its really necessary.
look for the keyboard_check() function in the help file, put this in a script or a piece of code action under the step event.
2 ways of making the object move, either change its x and y values directly
or give it a speed and direction e.g. speed = 10; direction = 270;
its easier to just run the movement code inside the relevant keyboard events rather than checking the
keyboard manually in the step event.
RougueSpear
06-02-2009, 08:10 PM
Hey and i am new.
But i have experience with yoyogames's forums and game maker.
But let me jump to my question:
I still by NAG every month but the older volumes I dont have and I would just like to know
where i can find all or the final golem master project which was done in 2006 in NAG?
I am busy with games of my own but I am eager to end this. Or see the end product?
RougueSpear
06-02-2009, 08:12 PM
Sorry i was in a hurry but I am sure you understand...
SplaT
08-02-2009, 07:59 PM
Just a quick question if I may:
Is it possible to use a string as an object name?
eg;
fname = "sav.txt"
f_id = file_text_open_read(fname);
global.sav = file_text_read_string(f_id);
file_text_readln(f_id);
file_text_close(f_id);
instance_create(x,y,global.sav)
Now this would obviously not work, since global.sav is a string.
Is there anyway I could make the game see it as an object name instead?
SkinkLizzard
08-02-2009, 09:15 PM
execute_string("instance_create(x,y,"+global.sav+")")
would work but its not ideal.
SplaT
09-02-2009, 12:55 AM
Yeah, I have seen that solution before, but most people say it's usually a bad idea to use the execute_string function.
Also, I wasn't sure how to use it.
Thanks.
EDIT: Great! Seems to be working fine!
dislekcia
09-02-2009, 01:03 AM
Just a quick question if I may:
Is it possible to use a string as an object name?
eg;
Now this would obviously not work, since global.sav is a string.
Is there anyway I could make the game see it as an object name instead?
Those object names actually map to integers, so you could simply not write the save file as the string name, but as the integer identifier. Then your code would work fine :) Except you wouldn't read in a string. And saves across versions might not work too well all the time.
SplaT
09-02-2009, 04:13 AM
I see what you mean. I tried what you suggested, to see if it would work better in my case.
I am using a seperate object for each puzzle of my game, so when the player quits, the next time the player opens up the game again, I want them to start where they left off.
At least just for now.
At the moment I have two scripts:
fname = "sav.txt"
f_id = file_text_open_write(fname);
file_text_write_string(f_id,string(global.sav));
file_text_writeln(f_id);
file_text_close(f_id);
fname = "sav.txt"
f_id = file_text_open_read(fname);
global.sav = file_text_read_string(f_id);
file_text_readln(f_id);
file_text_close(f_id);
return global.sav
The object name is the puzzle level and in the creation event of each object is:
global.sav = object_index;
save_game();
And in a controller object:
if file_exists("sav.txt")
{
load_game()
instance_create(room_width/2,room_height/2,global.sav);
}
else
instance_create(room_width/2,room_height/2,one);
So say the player left when he/she reached level 4, and the object index of object four is say 16.
This should work then, shouldn't it?
If I replace the global.sav var with a 16 instead of a var, it works, but otherwhise it just creates the first object, I surmise the object with the index of 0 is created for some reason.
In debug mode, it seems to read global.sav fine.
dislekcia
09-02-2009, 12:01 PM
Firstly, you might want to simply count how many puzzles the player has successfully passed and save that instead of an object index. Then you can read in that number and proceed from there, spawning the appropriate object as needed:
switch (global.completedPuzzles) {
case 0 : instance_create(0, 0, Puzzle1);
break;
case 1 : instance_create(0, 0, Puzzle2);
break;
...
case n : instance_create(0, 0, Puzzle<n+1>);
break;
}
Secondly, you're always getting a 0 return when you read from the file because you're asking it to read in a string ;) Use file_text_read_real() instead.
SplaT
09-02-2009, 12:26 PM
file_text_read_real!!
Oh, ponies... I'm so bad at this.
Thank a million, I would never have realized that by myself.
Though the switch statement method seems easier, once I run into a problem like this one, I'm irritatingly determined to figure out how to solve that problem.
Edit:
This is probably just me being stupid, but something like Puzzle<n+1> doesn't seem to be valid.
I'm getting Unexpected symbol in expression.
dislekcia
09-02-2009, 02:16 PM
Edit:
This is probably just me being stupid, but something like Puzzle<n+1> doesn't seem to be valid.
I'm getting Unexpected symbol in expression.
That'd be because it's pseudo-code, basically I'm saying that if you have n options, you should keep going by counting 1, 2, 3, 4, 5, etc until you get to n. It's not supposed to be any sort of special magic code in GM or anything ;)
SplaT
09-02-2009, 04:16 PM
That'd be because it's pseudo-code, basically I'm saying that if you have n options, you should keep going by counting 1, 2, 3, 4, 5, etc until you get to n. It's not supposed to be any sort of special magic code in GM or anything ;)
I understand that, though.
But even replacing it with instance_create(x,y,Puzzle(1+1)) is not accepted as Puzzle2
Unless I'm much mistaken, that means I'd have to manually add each object in the switch statement.
And since there are already 30+ objects (and counting), wouldn't it be simpler just to use the index of each object like the previous code? Since it's loading code is basically a one liner.
I also understand that the saved index might cause problems in a later version. So if manual is the only way, then so be it.
dislekcia
09-02-2009, 05:07 PM
I understand that, though.
But even replacing it with instance_create(x,y,Puzzle(1+1)) is not accepted as Puzzle2
Unless I'm much mistaken, that means I'd have to manually add each object in the switch statement.
And since there are already 30+ objects (and counting), wouldn't it be simpler just to use the index of each object like the previous code? Since it's loading code is basically a one liner.
I also understand that the saved index might cause problems in a later version. So if manual is the only way, then so be it.
Heh, you can't use logic like "Puzzle(1+1)" to get the identifier for Puzzle2. Unless Puzzle() was a script function you wrote that returned that kind of value ;)
Yes, in a switch statement you'd have to write that manually. This is why we have copy and paste. Also, use whichever approach works for you, I was just pointing out a possible problem in future and an alternate method to use. Maybe later you'll run into a problem that is switch shaped, then you'll know exactly what to do :)
SplaT
09-02-2009, 06:13 PM
Yes, absolutely.
Thanks a lot for you advice, I really do appreciate it.
Also, your patience is admirable.
:D
Bonezmann
03-03-2009, 09:32 PM
Hi there, I'm making a prototype for a "paddle'-type game. Since I don't know jack about basic "AI" even in paddle, I can't seem to make the enemy paddle follow the ball ONLY vertically, I've tried the following, using the graphics Interface of GM7:
Attempt 1
In the step event of paddle2:
Step towards ball.x ball.x(and both in ball.y too)
if hspeed is more than 0 then set hspeed to 0
(The paddle goes after the ball normally, ignoring my hspeed commands.
Attempt 2
Set vertical speed to ball.x(tried both ball.y too)
if vspeed is larger 5 then set vspeed to 5
(The paddle moves down, but doesn't follow the ball. It just goes down)
There are more attempts, but I'm not listing them coz I'm at the point where this thing is starting to irritate me in a bad way. Any suggestions? (I really have tried everything I can think of)
dislekcia
03-03-2009, 11:00 PM
Hi there, I'm making a prototype for a "paddle'-type game. Since I don't know jack about basic "AI" even in paddle, I can't seem to make the enemy paddle follow the ball ONLY vertically, I've tried the following, using the graphics Interface of GM7:
There are more attempts, but I'm not listing them coz I'm at the point where this thing is starting to irritate me in a bad way. Any suggestions? (I really have tried everything I can think of)
Ok. Couple of misunderstandings here... You need to try to visualise those properties in Game Maker as the objects move around, it should help you figure out the logic you're looking for.
An object's x position is it's horizontal position, from left to right, in a room. x = 0 at the far left edge of a room, x = room_width at the far right edge. An object's y position is it's vertical position, from top to bottom, in a room. y = 0 at the top of a room, y = room_height at the extreme bottom.
An object's hspeed is a measure of how far the object moved horizontally (ie, along the x direction) last frame. hspeed is positive if the object is moving right, negative if it's moving left. vspeed is a measure of how far the object moved vertically (ie, in y) last frame, positive if moving down, negative if moving up.
An object's hspeed and vspeed are intimately tied to it's speed and direction properties. If any member of those pairs are changed, the other pair is recalculated: So if hspeed is changed, speed and direction are recalculated; If direction is changed, hspeed and vspeed are recalculated... They're both ways of saying the same thing, after all: Telling an object how far to move next frame and in what direction.
You can also move an object directly, by changing its x and y positions yourself. This does not recalculate anything, it just changes where the object is right now ;)
So, if you want a paddle to move vertically, what should you be changing? Let's look at what you tried to do:
Attempt 1:
Step towards changes the x and y properties of an object immediately, hspeed doesn't come into account at all. That's why your attempt to limit the hspeed doesn't seem to make a difference.
The best idea here would have been to use step towards paddle.x, ball.y. Can you tell me why?
Attempt 2:
Setting the vertical speed to the ball's x value is probably always going to mean that the paddle's vspeed is always greater than 0 (unless the ball is outside the room to the left, remember about x and y positions?) so that explains why the paddle always moves down.
The way to use this approach would be to use a little maths (and the right property, in this case the ball's y position) to figure out how to move the paddle:
vspeed = y - ball.y;
if (vspeed > 5) vspeed = 5;
if (vspeed < -5) vspeed = -5;
What am I doing in that one? Pay special attention to the y - ball.y part, what am I really calculating there?
Bonezmann
04-03-2009, 06:16 PM
An object's x position is it's horizontal position, from left to right, in a room. x = 0 at the far left edge of a room, x = room_width at the far right edge. An object's y position is it's vertical position, from top to bottom, in a room. y = 0 at the top of a room, y = room_height at the extreme bottom.
An object's hspeed is a measure of how far the object moved horizontally (ie, along the x direction) last frame. hspeed is positive if the object is moving right, negative if it's moving left. vspeed is a measure of how far the object moved vertically (ie, in y) last frame, positive if moving down, negative if moving up.
An object's hspeed and vspeed are intimately tied to it's speed and direction properties. If any member of those pairs are changed, the other pair is recalculated: So if hspeed is changed, speed and direction are recalculated; If direction is changed, hspeed and vspeed are recalculated... They're both ways of saying the same thing, after all: Telling an object how far to move next frame and in what direction.
You can also move an object directly, by changing its x and y positions yourself. This does not recalculate anything, it just changes where the object is right now
Thanx for clearing that out, I always get confused with x and y :D
Attempt 1:
Step towards changes the x and y properties of an object immediately, hspeed doesn't come into account at all. That's why your attempt to limit the hspeed doesn't seem to make a difference.
The best idea here would have been to use step towards paddle.x, ball.y. Can you tell me why?
I'm going to try and give the best answer I can. Here goes:
x represents the horizontal position of the object, I don't want the paddle to move horizontally so I use it's own 'x' as a 'destination'. y represents the vertical position of the object, I want the paddle to move vertically so I set it to follow the vertical 'spot' of the ball, thus making it move up and down along with the ball. If you don't understand what I wrote above, don't worry. I know what you tought me, I just don't know exactly how to explain it myself. ;)
Attempt 2:
Setting the vertical speed to the ball's x value is probably always going to mean that the paddle's vspeed is always greater than 0 (unless the ball is outside the room to the left, remember about x and y positions?) so that explains why the paddle always moves down.
The way to use this approach would be to use a little maths (and the right property, in this case the ball's y position) to figure out how to move the paddle:
vspeed = y - ball.y;
if (vspeed > 5) vspeed = 5;
if (vspeed < -5) vspeed = -5;
I sat and thought about this one the entire afternoon(phone browsing FTW) and I just can't figure it out... :(
SplaT
05-03-2009, 12:40 AM
Did you figure it out yet?
Here is an example of what I -think- you are trying to do, I might be wrong though.
linky (http://willhostforfood.com/dl.php?fileid=57520)
dislekcia
05-03-2009, 01:45 AM
x represents the horizontal position of the object, I don't want the paddle to move horizontally so I use it's own 'x' as a 'destination'. y represents the vertical position of the object, I want the paddle to move vertically so I set it to follow the vertical 'spot' of the ball, thus making it move up and down along with the ball. If you don't understand what I wrote above, don't worry. I know what you tought me, I just don't know exactly how to explain it myself. ;)
Sounds like you've got the logic figured out there, nice :)
Remember that method of thinking, it's very useful when making games.
I sat and thought about this one the entire afternoon(phone browsing FTW) and I just can't figure it out... :(
Don't worry, you'll realise what that minus is all about soon enough ;)
The Dash
10-03-2009, 05:36 PM
Okay this is more math fail than anything else, its basically linear programming and feasible region
http://i39.tinypic.com/dw5cmu.jpg
Okay,
When mouse is on the side of the line where Mouse A is, [code]
Where Mouse b is it shouldn't work (This is where i need help) [NO code]
Mouse doesn't work in red part [NO code]
The two points of the line are (x,y) and (x2,y2) (no definite values as it changes)
Could someone please help with a formula that i can use to determine if the mouse is on the correct side of the line?
(Hope i explained it clearly)
Agrajag
10-03-2009, 06:41 PM
Well, Dash, what I would do is first define my line as a mathematical relation, the standard form of a straight line being y=mx+c (where m is your gradient, c is your y intercept). You can find m by calculating (y2-y)/(x2-x) and then find your c by substituting one of your points into the equation.
This is the important part: When you want to check your mouse location in relation to the line, substitute the mouse x value into the y=mx+c equation and check if the mouse y is greater or less than the y value on the line given by the equation.
It's really just a question of geometry. Just be careful about how you picture it in your head since it will probably end up inverted from anything that you've done on a cartesian plane because in programming an increasing y value is usually down.
dislekcia
10-03-2009, 06:50 PM
Okay this is more math fail than anything else, its basically linear programming and feasible region
http://i39.tinypic.com/dw5cmu.jpg
Okay,
When mouse is on the side of the line where Mouse A is, [code]
Where Mouse b is it shouldn't work (This is where i need help) [NO code]
Mouse doesn't work in red part [NO code]
The two points of the line are (x,y) and (x2,y2) (no definite values as it changes)
Could someone please help with a formula that i can use to determine if the mouse is on the correct side of the line?
(Hope i explained it clearly)
This is a classic case for parametric lines and linear algebra... Except real, useful, linear algebra instead of that crap they teach you at school ;)
First up, parametric line representation.
This is awesome, because it can be used to do hordes of cool things, most notably it deals with a lot of the problems on PC of having a line defined by y = mx + c.
Ask yourself "Self, what does a line do?" "... Join two points." your self should reply. So to parametrically represent a line we need two points. But what about where on a line something is? We can represent that by using a scalar value from a starting point... At 0 it's at the first point, at 1 it's at the second point, at 0.5 it's halfway between the two and at -1 it's on the far side of the starting point. With me so far?
So we can calculate a point at distance d on the line using P(d) = A + d(B - A) which is a point + a vector * a value, functionally in GM you'll have two different calculations for the x and y values of the new point (A is made up of an x and a y component, as is B), but we're only really touching on this so that you understand the notation.
Ninja maths, go!
Next, we've got a bunch of linear algebra techniques that let us figure out certain things... Imagine anime characters shouting out attack names. It's something like that ;)
We've got a dot product which lets us figure out the angle between two vectors. Doesn't sound too useful until we realise that we can project one line onto another by plugging in the number we get out of a dot product into the line's parametric equation. Again, not really amazing. But what if we turn the line 90 degrees? Then, if we calculate a dot product from the start of the line to the mouse and the new, perpendicular line, we get a number which tells us which side of the mouse the line is on! If it's negative, it's on the one side, if it's positive, it's on the other (depending on how we turned our line) and if it's 0, then the mouse is directly on the line.
We've also got a cross product, which gives us the perpendicular vector given two other vectors. Except that works in 3D... But if we pretend that we are actually in 3D, then we can figure out which side of a line the mouse is by taking the cross product of that line and a line from the starting point to the mouse point and seeing if that points in to or out of the screen. (Because that's where the third dimension would be, right?). If it points in, it's on one side, if out it's on the other. Just like the dot product technique.
Amazingly enough, both simplify down to the same maths in the end! Like I said, ninja. And a side effect of pretending to be in 3D and thus having some useful 0's ;)
Code:
First we need to create two vectors, we're going to call them A and M. A is the line we care about, M is the line from the starting point of A to the mouse.
Ax = (x2 - x1); //We're calculating a vector here, like the (B - A) part in the line equation
Ay = (y2 - y1);
Mx = (mouse_x - x1);
My = (mouse_y - y1);
Now that we've got our vectors (it's important that they start in the same place, here that's x1, y1), we can calculate our dot product of the perpendicular line (or the Z value of the cross product, whichever you like):
product = (Ax * My) - (Ay * Mx);
That's it. Now we just need to see which part of the line we're on:
if (product > 0) { ...left hand side, MouseA in your example... }
if (product < 0) { ...right hand side, MouseB in your example... }
There you go. Hope that helps ;)
The Dash
10-03-2009, 07:30 PM
...Extremely helpful stuff...
Thank you :D
**Places cake at Dislekcia's feet and walks out backwards, bowing sporadically
Jeronkey
17-03-2009, 02:59 PM
Is there some sort of law that prevents the Up directional key from working if Left and Right are held down? Left, Right and Down work together.. even Left, Right, Up on the number pad works. Just not when using the normal directional keys.
I can fix this problem by using a different set of keys, but I'm posting it here anyway out of curiosity.
Nandrew
17-03-2009, 03:12 PM
Well, sometimes keyboard manufacturers kinda have it so that you can't press a whole bunch of keys down and have them ALL register at once -- goodness knows that I had some grief with Frets on Fire when it turned out I couldn't hit some trip notes because the keyboard didn't like me pressing 1,2,3 and ENTER at the same time.
That almost sounds like the issue with your system, though I find it odd that the arrow keys would be affected thusly. It's definitely not some freak of coding accidents, then?
Jeronkey
17-03-2009, 03:19 PM
Well, sometimes keyboard manufacturers kinda have it so that you can't press a whole bunch of keys down and have them ALL register at once -- goodness knows that I had some grief with Frets on Fire when it turned out I couldn't hit some trip notes because the keyboard didn't like me pressing 1,2,3 and ENTER at the same time.
That almost sounds like the issue with your system, though I find it odd that the arrow keys would be affected thusly. It's definitely not some freak of coding accidents, then?
I thought it might be, so I started up a blank project. I set up an object to move about with those keys and it still didn't work. Also, it was a friend who first discovered it on his PC... perhaps we both just have terrible keyboards. ^_^''
Bonezmann
24-03-2009, 06:32 PM
OKay, I'm trying to make a a sprite face where the mouse pointer is(iow rotate). I went to the help file of GM7 and found this
Then, in the step event of the object you can set
{
image_index = direction * image_number/360;
image_speed = 0;
}
Could someone explain this to me? Would this help me? If not, what would?
SplaT
24-03-2009, 07:16 PM
I'm sure just a simple:
image_angle = point_direction(x,y,mouse_x,mouse_y)
would suffice.
Agrajag
24-03-2009, 07:46 PM
That code from the GM help file would work, but it relies on you having in your sprite 360 images, one facing at each angle. It was probably preceded by an explanation on how to generate that automatically. The idea is that
image_index = direction * image_number/360;
would set the image being displayed to the one corrosponding to the correct angle. For your case, you would need to replace "direction" with "point_direction(x,y,mouse_x,mouse_y)" so that it can work out the angle to make your sprite face the mouse.
image_speed = 0;
would stop your sprite from changing away from that image.
You can use
{
image_angle = point_direction(x,y,mouse_x,mouse_y)
}
Which would simplify the process and produce a better result, but only if you're using the pro version of game maker.
Bonezmann
24-03-2009, 08:21 PM
Thanx everyone!
Now I can make someone to shoot chickens crossing the road :D
Bonezmann
19-04-2009, 04:48 PM
Hi guys, I'm busy with a 3D game, using an extension I got from yoyogames.com. I made a cone(the player) with a texture and all and everything's working well. However, I want the cone/player to rotate along with the camera. As it is now, the camera rotates but not the cone/player, it does move in all directions though. I've tried some of the UI commands from the extension pack, and I have checked (although not thorouly) in the help file.
I'd really appreciate any help. Any idea on how I can rotate my cone/player?
Thanx in advance :)
Gazza_N
19-04-2009, 08:09 PM
Normally you'd use GM's transformation functions to rotate meshes, but I don't know how that extension you're talking about goes about doing stuff. In regular GM 3D, you'd slap the following in the Draw event:
d3d_transform_set_identity();
d3d_transform_add_rotation_z(direction to rotate in degrees);
d3d_transform_add_translation(x of object,y of object ,z of object);
d3d_draw_cone(-width/2,-breath/2,0,width/2,breadth/2,height,texture,hrepeat,vrepeat,closed,steps);
d3d_transform_set_identity();
Transformations are done relative to the origin, so you need to draw your cone to be centered around coordinates 0,0,0 in order for the transformations to work correctly. Of course, like I say, I don't know how your extension does things. Could be that the above won't work.
Funnily, I just finished covering transformations for Dev.Mag. I don't know when the article will be up, but it pretty much answers how you go about doing rotations and such using regular GM.
Bonezmann
19-04-2009, 08:34 PM
Okay, I changed the code you gave me. Although I'm not sure what to put in at the "hrepeat,vrepeat,closed,steps);" fields:
this is my code
d3d_transform_set_identity();
d3d_transform_add_rotation_z(45);
d3d_transform_add_translation(x,y,z);
d3d_draw_cone(-10/2,-10/2,0,10/2,10/2,20,player,-10,-10,-10,-10);
d3d_transform_set_identity();
I have exchanged the (x,y,z) fields with 0,0,0 as well. However, when I start my game ALL the textures are black. Any advice?
Gazza_N
19-04-2009, 08:52 PM
Sorry, the code I provided used generic variable names. I'll try to clarify.
First and last lines stay the same. No problem. Second line is good.
The third line tells GM how far to shift the mesh from the origin once it's been rotated. x and y obviously refer to the x and y of your object. "z" probably doesn't exist in your game as a variable, but it refers to how high from the "floor" you're placing your mesh. Assuming that your entire game takes place on one flat plane, stick 0 there for now.
The cone drawing function is simple, once you know what everything does. Your first six arguments look fine, but why not substitute the 10/2 with a plain old 5? ;P
You've placed "player" as your texture ID. I don't know how your framework references textures, so I can't give exact instructions here. Put -1 there for now, to make it blank, then 1 and 1 for your vrepeat and hrepeat arguments (they specify how many times the texture gets repeated across the mesh). The final argument specifies how many faces you want to make up your cone. More means a smoother cone with more faces, less means a chunkier cone. I'd recommend you put 16 in for now.
As for the blackness, there are two possibilities. Firstly, be sure that you haven't enabled lighting. After all, if you have lighting enabled with no lights, it'll all be dark. Duh. :P Secondly, be sure to set the draw colour to white using the draw_set_color(c_white) command. If you don't, meshes will be drawn in black by default, even the ones with textures.
Bonezmann
19-04-2009, 10:22 PM
d3d_transform_set_identity();
d3d_transform_add_rotation_z(45);
d3d_transform_add_translation(0,0,0);
draw_set_color(c_white)
d3d_draw_cone(-5,-5,0,5,5,5,player,1,1,-1,1);
d3d_transform_set_identity();
Okay, so this is how my code looks now. The draw_set color thing worked, but now there is no model? I'm really confused here, especially with the d3d_draw_cone(-5,-5,0,5,5,5,player,1,1,-1,1); line. I think you missed one argument?
edit:
Okay, I got the model to show. But now I'm back at square one. The model moves, but it doesn't rotate
editedit:
nvm, got it working. d3d_transform_add_rotation_z(45); had to be d3d_transform_add_rotation_z(direction);
Thanx alot Gazza_N \o/
Gazza_N
20-04-2009, 09:35 AM
You're welcome! I'm glad you got it running! :D
Bonezmann
21-04-2009, 10:05 PM
Right, so I'm still busy with the 3D Pea game. Now I've got a block I want my Pea to jump onto. However, I just can't seem to get the pea to stay on top of the block. I did once, but I did this:
In collision with object_wall
z=30
This sets my Pea on top of the block, but it goes on top of the block even if the pea walks into it.
Could anyone please point me in the right direction?
Gazza_N
22-04-2009, 01:41 PM
Remember this: even in 3D mode, Game Maker is a 2D game engine. This means that anything you do on the z axis needs to be handled by YOU. ;)
Basically, you need to set up a "collision prism". You'll need to expand the collision code a little. Firstly, I suggest giving your wall/block "z" and "height" variables. "z" will reflect the block's base z value, and in "height" you'll stick the block's height (if it's a perfect block like I've seen in your screenies, the height'll be the same as the width and breadth). Next, in your pea's collision event, you'll need add code to check the pea's z value versus the block's when they collide on the x and y axes. If the Pea's z value is larger or equal to the block's z+height when they collide, set it so that the pea won't drop lower than the block's surface. If its z is under that value, have it collide against the wall normally.
Bonezmann
22-04-2009, 02:27 PM
Remember this: even in 3D mode, Game Maker is a 2D game engine. This means that anything you do on the z axis needs to be handled by YOU. ;)
Basically, you need to set up a "collision prism". You'll need to expand the collision code a little. Firstly, I suggest giving your wall/block "z" and "height" variables. "z" will reflect the block's base z value, and in "height" you'll stick the block's height (if it's a perfect block like I've seen in your screenies, the height'll be the same as the width and breadth). Next, in your pea's collision event, you'll need add code to check the pea's z value versus the block's when they collide on the x and y axes. If the Pea's z value is larger or equal to the block's z+height when they collide, set it so that the pea won't drop lower than the block's surface. If its z is under that value, have it collide against the wall normally.
Thanx Gazza, I'll experiment a bit and see what I can come up with.
Bonezmann
22-04-2009, 03:56 PM
I've got a second floor in my level.
here is my code: in my Pea's collision with floor2
if z<floor2.z then z=0
else z=120
My problem is that when I move underneath floor2 my Pea suddenly appears on top of floor2.
Any pointers?
(This is all on my way to collision detection in 3D :D)
Gazza_N
22-04-2009, 06:48 PM
Huh. O_O
Remember that if you use the object type as a handle, it checks ALL objects of that type. It could be that you need to narrow it down to the specific floor you're colliding with. In GM collision events, it gives you the "other" handle to reference the specific instance you're colliding with. Try this:
if(z<other.z){z=0;}
else{z=other.z;}
This code assumes that the pea isn't going to do any jumping or have any z changes during the collision, of course.
Bonezmann
22-04-2009, 06:51 PM
Thanx Gazza, I'll try that and see if it works. :)
edit: nope, nothing. Maybe there's something wrong elsewhere
dislekcia
22-04-2009, 08:26 PM
Thanx Gazza, I'll try that and see if it works. :)
edit: nope, nothing. Maybe there's something wrong elsewhere
Ok, Bonezmann, the GM collision events are only 2D. I'm assuming you're drawing things in the 3D world at locations relative to their x, y positions in your room? That's useful most of the time, but confusing when it comes to collisions. Essentially, imagine your map from above. Every time one object is in the same space as another, that's going to be a collision in GM. A 2D only collision.
The reason your player is being placed on the second floor all the time is because you're telling it to be there every time it gets a 2D collision event. Make sense?
Bonezmann
22-04-2009, 08:38 PM
Ok, Bonezmann, the GM collision events are only 2D. I'm assuming you're drawing things in the 3D world at locations relative to their x, y positions in your room? That's useful most of the time, but confusing when it comes to collisions. Essentially, imagine your map from above. Every time one object is in the same space as another, that's going to be a collision in GM. A 2D only collision.
The reason your player is being placed on the second floor all the time is because you're telling it to be there every time it gets a 2D collision event. Make sense?
I get they are only 2D, and I get the whole 2D collision thing, but (and correct me if I'm wrong) according to the following code in the collision between the Pea(player) and the 2nd floor object, named floor2:
if z<floor2.z then z=0
if z=floor2.z then z=120
the pea shouldn't do that, because I use the z location and not the x or y? I'm confused to hell and back here. Yes, the collision happens in 2D(x and y) but didn't I specifically tell it to react to z? again, VERY confused... @_@
Gazza_N
22-04-2009, 09:00 PM
Bonez, the only thing that I can think of is that somewhere your z variable is being set to be above that second floor's z, that your floor z isn't what you think it is. Have you declared z in your pea object as being zero? Are there any other bits of code that could be accidentally be increasing its z value when you don't want it to be increased? Are you sure that floor2.z corresponds to the height you want (I still recommend using the "other" handle for that check, BTW. More precise)? Logically, that code should work, but I'm pretty sure that somewhere that z variable is being messed with or was declared incorrectly.
Bonezmann
22-04-2009, 10:26 PM
Bonez, the only thing that I can think of is that somewhere your z variable is being set to be above that second floor's z, that your floor z isn't what you think it is. Have you declared z in your pea object as being zero? Are there any other bits of code that could be accidentally be increasing its z value when you don't want it to be increased? Are you sure that floor2.z corresponds to the height you want (I still recommend using the "other" handle for that check, BTW. More precise)? Logically, that code should work, but I'm pretty sure that somewhere that z variable is being messed with or was declared incorrectly.
I think I'm going to delete the extension pack and just take a hell lot of tutorials or something. If I can't get it right, Pea3D will have to wait. I'm not going to get over-hasty and confuse myself. I'd rather start from scratch with a decent tutorial or two.
Thanx for all the help anyways guys :)
SkinkLizzard
23-04-2009, 12:33 PM
gamemaker can be random sometimes
and although in general it understands most syntax, perhaps
just make sure you use == for comparisons and = for assignment.
when I get home tomorrow I'll ask my younger brother he's done gamemaker 3D
and more than one floor so he should be able to help.
Gazza_N
23-04-2009, 12:40 PM
Would you mind posting your source, Bonez? If I can see exactly what's going on, I can help better. ;)
Bonezmann
23-04-2009, 09:18 PM
Would you mind posting your source, Bonez? If I can see exactly what's going on, I can help better. ;)
My object/sprite names and trees are generally chaos, but you could try. Keep in mind that I use the extension, which I'll send along. :)
Aval4nche
03-05-2009, 06:59 PM
How would I go about getting objects to stay in view when the view is moving? I tried jumping to view_xview view_yview but it causes annoying jiggle when the block keeps getting to a location, remembering its code, seeing that it needs to jump again and jumps again and repeats. I need a better way!
The Dash
03-05-2009, 08:26 PM
How would I go about getting objects to stay in view when the view is moving? I tried jumping to view_xview view_yview but it causes annoying jiggle when the block keeps getting to a location, remembering its code, seeing that it needs to jump again and jumps again and repeats. I need a better way!
drawing the location would make it smoother, also jumping it in the draw event
Alternatively, use "Object following" in room properties-views tab
Aval4nche
04-05-2009, 04:53 PM
Thanks, I'll try it out later.
01DT!m3r
04-05-2009, 09:09 PM
@Avalanche .in the event that moves your view have you tried setting the x and y co-ords of the object by the same displaced amount?
Aval4nche
05-05-2009, 03:05 PM
Yeah. The view is focused on another object, so it looks like I might have to keep that object firmly in the center of the screen.
Edit: Stuff it, I'm rather going to make it keyboard presses instead of objects you must click. It will probably be better that way anyway ;D
SplaT
11-05-2009, 10:43 PM
Righto. I require some help again if I may.
I'm trying to create a basic auto attack-move feature in my prototype.
I have tried many different ways, and I have given up.
Here is the basic idea.
http://i202.photobucket.com/albums/aa162/UnpaidWizard/Example.png
Firstly, the enemy and ally objects are the same, since the factor of which player they belong to depends on where they spawn.
Now the mission for one of these units to get to the enemy target on the other side, while attacking enemy units on the way.
Though I'm not there yet, since I'm firstly having trouble defining the Nearest Enemy.
This is the code I ended up with:
if creepPlayer = -1
{
if y < room_height/2
{
creepPlayer = 0
NearestEnemy = Destination_South_obj
}
else
{
creepPlayer = 1
NearestEnemy = Destination_North_obj
}
}
with creep_obj{
if distance_to_object(other)<100
{
if creepPlayer != other.creepPlayer
{
NearestEnemy = instance_nearest(x,y,other);
}
}
}
path_end()
mp_grid_add_instances(grid,obj_block,true)
mp_grid_path(grid,path,x,y,NearestEnemy.x,NearestE nemy.y,false)
path_start(path,argument0,0,true)
When an object is created, a boolean variable (creepPlayer) is set to depending on where they spawn, basically it's set to 0 or 1, North and South respectively.
Though I'm having trouble having the units identify which instances are enemies have them set the closest enemy position as their new destination.
I've also tried things like collision_circle, maps and lists. All of which I failed in.
if collision_circle(x,y,100,Imp_obj,1,1)
{
if other.creepPlayer != creepPlayer {
NearestEnemy = other
}
}
I'm not sure about this one, though. The help file says that collision_circle returns the id of the object it collided with, while other people said it returned whether or not there was in fact a collision.
Anybody care to give a wittle noob a helping hand?
I promise I'll appreciate it.
Nandrew
12-05-2009, 12:25 AM
I've been in the very same situation myself. Quite a few times, in fact! :P
Just a quick note before I start my explanation:
I'm not sure about this one, though. The help file says that collision_circle returns the id of the object it collided with, while other people said it returned whether or not there was in fact a collision.
It kinda does both. If there's no collision, it returns zero or a negative value (can never remember which). If there IS a collision, you can be your granny's knickers that it'll return the id of the offending instance.
-----
In the situation that you have here, I usually implement a rather inelegant solution, but a solution nonetheless.
When you assign your basic creep object its alliance variable, also make it create one of two follower objects: FollowRed or FollowBlue. In the code for each of these Follow objects, you'll want an "owner" variable: this will be assigned the value of the creep's instance id. Make the Follow object's x and y match the owner's xy at every frame.
Then, finding the nearest enemy becomes a trivial matter of checking the current object's alliance, then searching for instance_nearest on FollowRed or FollowBlue accordingly. Once you've grabbed that instance, refer to its owner variable.
You now have, without fail, the instance id of the nearest enemy creep.
I call this inelegant because you'll need to duplicate all of the code in FollowRed and FollowBlue: this should, however, not be a problem. Just keep the amount of code in these two objects to a minimum and maybe the programming gods will forgive you.
SplaT
12-05-2009, 10:27 AM
Hot dang! Thanks Nandrew.
I almost got it to work, but one last thing that I can figure out is how to set the target back to the main destination if no enemy creep exists.
I have this code, but it doesn't seem to work:
with FollowNorth_obj{
if instance_exists(FollowSouth_obj)=1{
target = instance_nearest(x,y,FollowSouth_obj)
}
else target = Destination_South_obj
}
with FollowSouth_obj{
if instance_exists(FollowNorth_obj)=1{
target = instance_nearest(x,y,FollowNorth_obj)
}
else target = Destination_North_obj
}
It seems to try and still set the target to the instance_nearest, regardless wheter the instance exists. Thus giving me a error, complaining about not knowing what target is.
Though it works 100% if the instance does exist.
Much appreciated.
EDIT:
Awesome, I got it to work.
I simply created a FollowObj instance on the Main Target aswell.
Problem solved.
Thanks, Nandrew, you rock.
dislekcia
12-05-2009, 12:10 PM
For future reference, you could avoid the whole follow object schlep by using parenting in GM:
1. Create an Enemy object that has health, etc.
2. Create RedEnemy and BlueEnemy that inherit from Enemy. You would make RedEnemies move towards the nearest instance of BlueEnemy and vice-versa.
3. Create special RedBase and BlueBase classes that inherit from RedEnemy and BlueEnemy respectively. These are the big bases that do the spawning, etc. Because they inherit from the correct enemy class, the other side's enemies will automatically move towards them if they're the closest instance of Red/BlueEnemy (which they will be if there are no other Enemies of that type, thanks to inheritance).
Also, in the code above this doesn't make sense:
with FollowSouth_obj{
if instance_exists(FollowNorth_obj)=1{
target = instance_nearest(x,y,FollowNorth_obj)
}
else target = Destination_North_obj
}
The bolded line will probably always return true. instance_exists() checks if a specific instance exists or not, so you want to check that against pointers to objects (useful if you've stored which object collided with something a few frames ago and it might have died in the mean time). Your check logic isn't quite right, you need to use two = signs to test something, one = attempts to assign a value, so you were probably always getting a "true" out of that, even if there were no instances of the type you were looking for. The best code to do that would be:
if (instance_number(Follow_South_Obj) > 0) {
} else {
}
Nandrew
12-05-2009, 12:18 PM
Oh snap, Danny's code thoroughly pwns mine. I can't believe I actually didn't just think of doing that.
SplaT
12-05-2009, 12:50 PM
The way I got it working is by creating two scripts. They are attack_move() and set_attributes().
When I create a new unit, all I have to do is is add something like this in the Step Event of the unit:
attack_move(speed);
And this in the Create Event:
set_attributes(hp,damage,ect...)
Meaning I only need one object of each unit I'm going to create.
Would it ultimately be better in terms of stability, ease of use, ect. to scratch my current code and create 2 seperate objects parented to a control unit instead?
Also, I totally forgot about the ==. But I did away with the instance_exists() code when I added the FollowObject to the Main Targets, since that would no longer be necessary.
Thanks a bunch.
I must say, I used to find stuff like this problem solving frustrating and dull, but I'm really enjoying creating this game.
Chippit
12-05-2009, 01:48 PM
Oh snap, Danny's code thoroughly pwns mine. I can't believe I actually didn't just think of doing that.
lol noob.
<Gorilla>
13-05-2009, 05:47 PM
noobi question but how do you make a sprite shoot? the tut makes little to no sense to me and my friend.
dislekcia
13-05-2009, 06:34 PM
noobi question but how do you make a sprite shoot? the tut makes little to no sense to me and my friend.
Which tutorial are you talking about? The scrolling shooter tutorial on the Yoyogames tutorial page (http://www.yoyogames.com/make/tutorials) is pretty straightforward :)
Shad0wstr1k3
26-05-2009, 07:04 PM
I am having major troubl with my new game: GravBlob
The idea of the game is to navigate levels and reach the exit. In this world there are boxes with arrows on them, these boxes manipulate gravity. For example if you stand on an UP box, your gravity will change and you will fall up.
My problem is the gravity change, I cant seem to get it right, I have tried many things, none of which work(for exaple saying what the starting gravity is in the create event, but then the charater doesn't walk)
Any idea's, Please.
Bonezmann
28-05-2009, 04:39 PM
Hi there, I recently found a code to insert .obj models into GM7. However the only model showing is my player model. No other model shows, and I set the color to c_white. any ideas? I'm willing to upload the source as long as you're willing to work with an extension. (just for interest sake, it's the Easy 3D Extension that can be found on the yoyogames website)
Help?
Kensei
28-05-2009, 05:41 PM
I am having major troubl with my new game: GravBlob
The idea of the game is to navigate levels and reach the exit. In this world there are boxes with arrows on them, these boxes manipulate gravity. For example if you stand on an UP box, your gravity will change and you will fall up.
My problem is the gravity change, I cant seem to get it right, I have tried many things, none of which work(for exaple saying what the starting gravity is in the create event, but then the charater doesn't walk)
Any idea's, Please.
Go find Nandrew, he should have a lot of experience with this (take a look at his Variance thread :P )
Hi there, I recently found a code to insert .obj models into GM7. However the only model showing is my player model. No other model shows, and I set the color to c_white. any ideas? I'm willing to upload the source as long as you're willing to work with an extension. (just for interest sake, it's the Easy 3D Extension that can be found on the yoyogames website)
Help?
Hmm. What does it show? just a white block? Or nothing?
Bonezmann
28-05-2009, 06:24 PM
Go find Nandrew, he should have a lot of experience with this (take a look at his Variance thread :P )
Hmm. What does it show? just a white block? Or nothing?
Nothing... even the floor tile is gone.
dislekcia
28-05-2009, 07:28 PM
Hi there, I recently found a code to insert .obj models into GM7. However the only model showing is my player model. No other model shows, and I set the color to c_white. any ideas? I'm willing to upload the source as long as you're willing to work with an extension. (just for interest sake, it's the Easy 3D Extension that can be found on the yoyogames website)
Help?
Change the order you load your objs in to test if you're loading them all to the same reference or something like that. GM extensions usually use reference ids to store things, so you need to make sure you're loading everything to a unique reference.
Bonezmann
28-05-2009, 07:54 PM
Change the order you load your objs in to test if you're loading them all to the same reference or something like that. GM extensions usually use reference ids to store things, so you need to make sure you're loading everything to a unique reference.
any pointers on how to do that?
edit: nvm, I got it working. Seems there was a "drag and drop" Create view button I had to remove in the other object's creation event. :)
Nandrew
31-05-2009, 03:37 PM
I am having major troubl with my new game: GravBlob
The idea of the game is to navigate levels and reach the exit. In this world there are boxes with arrows on them, these boxes manipulate gravity. For example if you stand on an UP box, your gravity will change and you will fall up.
My problem is the gravity change, I cant seem to get it right, I have tried many things, none of which work(for exaple saying what the starting gravity is in the create event, but then the charater doesn't walk)
Any idea's, Please.
I should check this thread more often. <_<
Hmm. It's a bit difficult offhand to say what your problem is, maybe with more description we'll be able to hack it out. Platforming collision and movement in Game Maker is a surprisingly dangerous beast, and getting in a nice system still irritates me to this day.
One piece of advice which I find applies quite often, though: using the collision event in the drag and drop interface (for example, the event that says "collision with WallBlock" or something) automatically stops your character's movement, which can interfere with your walking speed if, for example, your gravity is set to collide with the ground beneath you on a step-by-step basis.
You can override this stop mechanic by explicitly reconfiguring the vertical or horizontal speed of you character (for example set one of the two to zero) and make sure that you use "position collision" checks on your left and right sides to stop your character from bumping into walls.
Unfortunately, you may well have to reconfigure this depending on your different gravity directions, but it's the most elegant way that comes to mind without digging into GM code and hacking out your own collision system (which I usually do because I HATE how GM screws around with the default variables without my permission).
Nandrew
31-05-2009, 03:42 PM
Of course, what I would suggest most of all is to take a look at the Game Maker platforming tutorial (http://www.yoyogames.com/make/tutorials) to understand what's going wrong with your current system.
luenardi
31-05-2009, 05:28 PM
*ignore post.. sorry
kolle_hond
01-06-2009, 09:29 PM
Ok, I'm trying to make a fighting game and all is going surprisingly swiftly, one problem I have though is when the player attacks. I use a different object for the arm, when the attack button is pressed the sprite for the arm changes and hits the opponent reducing one life. The problem is if you hold the button in you reduce more life than one attack so to counter this I made the sprite change back as soon as the life is subtracted. This gives the problem that when you stand too close you cannot even see the attack, just the life of the opponent dropping. Any ideas how you can hit the opponent once and do one attack's worth of damage while actually seeing the attack at close range? Thanks
Bonezmann
01-06-2009, 10:29 PM
Ok, I'm trying to make a fighting game and all is going surprisingly swiftly, one problem I have though is when the player attacks. I use a different object for the arm, when the attack button is pressed the sprite for the arm changes and hits the opponent reducing one life. The problem is if you hold the button in you reduce more life than one attack so to counter this I made the sprite change back as soon as the life is subtracted. This gives the problem that when you stand too close you cannot even see the attack, just the life of the opponent dropping. Any ideas how you can hit the opponent once and do one attack's worth of damage while actually seeing the attack at close range? Thanks
I'm going on a limb here, but have you tried using alarms? how about calculating how much damage the attack does and just work it out? alternatively you can change the control method or limit the attack by using alarms so the attack won't "spam".
in your creation event:
global.attack=0
Once again, going out on a limb, but it won't hurt to try:
in the collision event between the attack sprite and the enemy add and play around with these:
if global.attack=0 then (the sprite/object should change)
if global.attack=0 then global.attack=1(make sure you put something like this AFTER the attack stuff, otherwise nothing will happen)
In your step event:
if global.attack=1 then (set your alarm to f.i 10 steps)
in alarm event:
global.attack=0
Play around with these and see if it helps a bit, until the experts give you some more advanced advice. That's how I would've done it. :)
kolle_hond
02-06-2009, 12:10 AM
I'm going on a limb here, but have you tried using alarms? how about calculating how much damage the attack does and just work it out? alternatively you can change the control method or limit the attack by using alarms so the attack won't "spam".
in your creation event:
global.attack=0
Once again, going out on a limb, but it won't hurt to try:
in the collision event between the attack sprite and the enemy add and play around with these:
if global.attack=0 then (the sprite/object should change)
if global.attack=0 then global.attack=1(make sure you put something like this AFTER the attack stuff, otherwise nothing will happen)
In your step event:
if global.attack=1 then (set your alarm to f.i 10 steps)
in alarm event:
global.attack=0
Play around with these and see if it helps a bit, until the experts give you some more advanced advice. That's how I would've done it. :)
I will try thanks, I don't go by the sprite, I made the arms and legs seperate objects from the main body, thus if they collide with the enemy the hitpoints get reduced. This also saved me some time drawing sprites but it might not look that good in the final product.
Edit: ok, I found a bit of a problem there, if I set the alarm in the step event the alarm never goes off, I'll try setting it at the button press.
Edit2: the code worked!
Bonezmann
02-06-2009, 05:55 PM
I will try thanks, I don't go by the sprite, I made the arms and legs seperate objects from the main body, thus if they collide with the enemy the hitpoints get reduced. This also saved me some time drawing sprites but it might not look that good in the final product.
Edit: ok, I found a bit of a problem there, if I set the alarm in the step event the alarm never goes off, I'll try setting it at the button press.
Edit2: the code worked!
What? Mine? O_O
kolle_hond
02-06-2009, 07:48 PM
What? Mine? O_O
yeah, lol, thanks.
The Dash
17-06-2009, 07:06 PM
Okay im trying to generate a random pattern of squares, this is the code:
val=choose(-96,96)
instance_create(x+val,y,objectFloor)
instance_create(x,y+val,objectFloor)
If i put "instance_create(x+val,y,objectFloor) " first, it generates a row of random length, 3 blocks high, if i reverse the order and put "instance_create(x,y+val,objectFloor)" first it generates a column of random height, 3 blocks wide.
In the create event of objectFloor it has
Snap to grid(96,96)
if number of instances<50 then
The code above
How do i get it to actually work, i've tried using a separate val for x and y, i even put the two create events separate
dislekcia
17-06-2009, 10:19 PM
Okay im trying to generate a random pattern of squares, this is the code:
val=choose(-96,96)
instance_create(x+val,y,objectFloor)
instance_create(x,y+val,objectFloor)
If i put "instance_create(x+val,y,objectFloor) " first, it generates a row of random length, 3 blocks high, if i reverse the order and put "instance_create(x,y+val,objectFloor)" first it generates a column of random height, 3 blocks wide.
In the create event of objectFloor it has
Snap to grid(96,96)
if number of instances<50 then
The code above
How do i get it to actually work, i've tried using a separate val for x and y, i even put the two create events separate
Ok... I'm assuming you want either a randomly spaced grid of 50 objectFloor instances, or you want them all over your room, snapped so that they align.
Is there any particular reason that you want the objects to be next to each other? Because with a width/height of 96 and moving things around by 96 units, you're never going to get an "open space".
The reason you're getting 3-high rows is pretty simple, given the way that you're never going to get spaces. You're basically re-executing that creation code every time you get to the first instance_create call, so you're getting a bunch of blocks that either move left or right from the starting one. Then those are creating more blocks that either move left or right from the block that created them. Until eventually you have 50 blocks (because it will only stop creating new blocks once it hits 50 in the create event test) all in the same row. ONLY THEN does the last block created go ahead and call the second instance_create, the one that moves blocks up or down. At this point it doesn't matter if the block's moving up or down, it's only ever going to be 1 row up or down from the initial row of 50. That new block will never create more blocks, because you're over 50 blocks already. That then carries on, backwards through all the create events of the blocks - spawning a new block only 1 row up or down - until you eventually get to the first created block and that finally gets to end its create event.
The solution is to move the code doing this outside the create event of the thing you're building. Basically create an invisible object that does something like this in its create event:
while (instance_number(objectFloor) < 50) {
//Pick random co-ordinates in the room, snapped to a 96,96 grid
testX = random(room_width div 96) * 96;
testY = random(room_height div 96) * 96;
if (instance_position(testX, testY, objectFloor) < 0) { //If there isn't a floor there already
instance_create(testX, testY, objectFloor); //Create one!
}
}
instance_destroy();
Insomniac
18-06-2009, 11:55 AM
Edit: Nevermind, SkinkLizzard helped me out :)
The Dash
18-06-2009, 12:00 PM
Is there any particular reason that you want the objects to be next to each other? Because with a width/height of 96 and moving things around by 96 units, you're never going to get an "open space".
I'm using it to randomly create a floor, each tile is placed next to each other to ensure that the player will always be able to get from one side of the floor to the other
The reason you're getting 3-high rows is pretty simple, given the way that you're never going to get spaces. You're basically re-executing that creation code every time you get to
...
only 1 row up or down - until you eventually get to the first created block and that finally gets to end its create event.
The solution is to move the code doing this outside the create event of the thing you're building. Basically create an invisible object that does something like this in its create event:
I thought about what you said, and just moved the create code to an alarm thats set to one step. now it works perfectly. you can see what it looks like here (http://drop.io/peggleaszombiesurvival)
kolle_hond
18-06-2009, 12:54 PM
ok, so I'm trying to get the effect of a 'scrolling' background.
if global.multipl = 1 then
begin
player2.hspeed = player2.hspeed + 5;
end;
if global.multipl = 0 then
begin
comp.hspeed = comp.hspeed + 5;
end;
This is on my press left for player1.
player2 isn't created when you play vs cpu and comp isn't created in multiplayer, thats where multipl = 0 for single player and 1 for multiplayer. My problem is that I still get the error:
Error in code at line 3:
player2.hspeed = player2.hspeed -5;
at position 27: Unknown variable hspeed
Is there a quick fix for this or a better way to create the effect?
dislekcia
18-06-2009, 01:06 PM
I'm using it to randomly create a floor, each tile is placed next to each other to ensure that the player will always be able to get from one side of the floor to the other
I thought about what you said, and just moved the create code to an alarm thats set to one step. now it works perfectly. you can see what it looks like here (http://drop.io/peggleaszombiesurvival)
Ah, I see. That explains the no gaps thing.
Have you dealt with the problem of your random code creating blocks on top of other blocks?
I'd write a system that created a filled area of blocks and then randomly removed one at a time until it reached a pre-specified limit. Each time something was removed, I'd check to see if that created any isolated block sections and replace it if it did.
The Dash
18-06-2009, 04:06 PM
Ah, I see. That explains the no gaps thing.
Have you dealt with the problem of your random code creating blocks on top of other blocks?
Yes I did
I'd write a system that created a filled area of blocks and then randomly removed one at a time until it reached a pre-specified limit. Each time something was removed, I'd check to see if that created any isolated block sections and replace it if it did.
You like doing things the hard way i see ;P
Evolution
23-06-2009, 10:57 AM
Recently none of the games made with game maker 7 will run on my pc. Any ideas of what could be the cause?
dislekcia
23-06-2009, 01:38 PM
Recently none of the games made with game maker 7 will run on my pc. Any ideas of what could be the cause?
Have you checked the official GM site for possible reasons/fixes? www.yoyogames.com
Evolution
23-06-2009, 04:03 PM
Have you checked the official GM site for possible reasons/fixes? www.yoyogames.com
Could it be a corrupt operating system file(s). Will installing xp service pack 2 maybe fix the problem and will the service pack wipe out any of my files.
Evolution
23-06-2009, 06:56 PM
Reinstalled sp2, scanned for corrupted windows files, reinstalled directx components, and still I can't run game maker games.
Evolution
23-06-2009, 07:45 PM
I seem to be able to run basic game maker games, but when I try running game maker games that use more features it doesn't run. The next logical thing was to start adding features into a game maker game until it broke and eventually came to the problem. My computer can't play game maker games that is playing a mp3.
Bonezmann
26-06-2009, 06:41 PM
A good place to start could be posting if it gives you an error message and what it contains? Does it just not run? Expand on the problem, tell us more... ;)
Evolution
26-06-2009, 09:20 PM
A good place to start could be posting if it gives you an error message and what it contains? Does it just not run? Expand on the problem, tell us more... ;)
If it runs a mp3 at the start of the room it crashes with an "unxpected error" message, and if I run a mp3 after a few seconds the room has been arround it stalls and continues running again with no sound.
zakeroph
02-07-2009, 04:25 PM
K here is what I am doing at the moment...
I have a plane that can fire when a variable can_shoot = 1, then after firing it sets the variable to 0, after that it sets an alarm...when the alarm goes it sets the variable back to 1. Using this i controlled how fast the plane can fire.
Now what I'm doing is i have made a power up that basically increases the rate of fire, so i just want to know what would be the best way to make the change in the plane object...or where ever i should make the change. I also want this change to be temporary.
I think I know how but i would like to hear if there is a "best" way to get this done.
dislekcia
02-07-2009, 06:24 PM
K here is what I am doing at the moment...
I have a plane that can fire when a variable can_shoot = 1, then after firing it sets the variable to 0, after that it sets an alarm...when the alarm goes it sets the variable back to 1. Using this i controlled how fast the plane can fire.
Now what I'm doing is i have made a power up that basically increases the rate of fire, so i just want to know what would be the best way to make the change in the plane object...or where ever i should make the change. I also want this change to be temporary.
I think I know how but i would like to hear if there is a "best" way to get this done.
The value that you set the alarm that resets can_shoot, simply make that a variable. That way you can have a default firing time when the ship is created, but you can change the firing time when you pick up your powerup and set a new alarm that resets the firing time value back to normal.
SkinkLizzard
02-07-2009, 08:57 PM
or do what dis said but have 2 variables one for base refire rate and one for modifier
then set the alarm to the product of the two. The power up can then give a percentage speed boost which is
really redundant but seemed cool at the time I used it.
zakeroph
03-07-2009, 08:28 AM
In the end i used a super_charged variable in the plane that gets set to 1 when it collides with the powerup, then an alarm sets it back to 0 after 30 seconds, if the variable is one it uses one timing for the alarm that sets the can_shoot variable and if the variable is 0 it uses the slower timing.
dislekcia
03-07-2009, 11:46 AM
In the end i used a super_charged variable in the plane that gets set to 1 when it collides with the powerup, then an alarm sets it back to 0 after 30 seconds, if the variable is one it uses one timing for the alarm that sets the can_shoot variable and if the variable is 0 it uses the slower timing.
That'll work, but it's not as flexible... If you make your timing a variable you can do things like have a slower fire rate if the ship is hit too often, etc. ;)
zakeroph
06-07-2009, 01:12 PM
oh ok, like i could then put something like
if obj_myplane.health//don't know if that's the right name>_<//then rate_fire = slower than normal fire rate
normal rate of fire set as the creation event
....but i just keep changing the rate_fire number and use that variable in the alarm timer?
dislekcia
06-07-2009, 06:53 PM
oh ok, like i could then put something like
if obj_myplane.health//don't know if that's the right name>_<//then rate_fire = slower than normal fire rate
normal rate of fire set as the creation event
....but i just keep changing the rate_fire number and use that variable in the alarm timer?
Yup, something very similar to that :)
There's one thing about working in GM with pointers and objects that a lot of people suffer with though: It helps to capitalise object types and keep variables lower case, or employ some other sort of identification, like you've done with "obj_". I just find capitals less hassle to type ;)
The reason for this is that if you use <object type>.<variable> it will return the value of that particular variable on the first instance of that object type. If you want a specific object, then you need to find a pointer to it via something like a collision (in a collision event, the special variable other is the instance that's being collided with) or another function that returns an instance pointer.
... I probably just confused you, didn't I?
zakeroph
07-07-2009, 08:28 AM
Surporisingly enough, not completely, thanks for the help :P
Somebody
17-07-2009, 02:47 AM
This is not a question about GM but about Delphi (I didn't see any other help threads). So lets say I have 500 images and I want to know how many of those images is in a circle around a specific point. So my question is should I manually write the code to test each one or is there something else I can use that will save me time? I was thinking of something along the line of using a variable and increasing it by 1 each time it tests the code and reading the whole code from the start.
Evolution
17-07-2009, 09:31 AM
If you want to make sure they are all fully in a given circle you can test the distance from the center of the circle too each of the corner points of the image, but if you don't need the whole image in the circle then you can test it with the center point of the image with the center of the circle.
Edit:
Or are you asking if the images are falling on the edge of a circle. Then you can check if at least on of the images' corners fall in the radius of the circle and at least on other point doesn't.
Somebody
17-07-2009, 12:10 PM
I know how to test it. My problem is just writing the codes to test 500 images is going to takes some time. Is there a quicker way to test 500 images without having to write a too long code?
Evolution
17-07-2009, 12:51 PM
you can use an array or a list to store the images, then have a function that checks for a collision in the image object, then you go through the list / array performing the collision checking
Somebody
18-07-2009, 02:52 PM
Heres an example of my code
var
images : array [0..39] of tlabel;
Procedure Tform1.timer1timer(sender: Tobject);
var
i : integer;
Begin
i := 0;
repeat
for i := 0 to 39 do
begin
images[i].left := Random(600);
images[i].top := Random(600);
end;
inc(i);
until i = 39;
Basicly I am putting the images in random places each time. But when I run it I get the following error message "Access violation at address 00434AAF in module 'Project2.exe'. Read of address 038BD113." I tried google but I got nothing.
The Dash
18-07-2009, 03:59 PM
var
images : array [0..39] of tlabel;
Procedure Tform1.timer1timer(sender: Tobject);
var
i : integer;
Begin
for i := 0 to 39 do
begin
images[i].left := Random(600);
images[i].top := Random(600);
end;
end;
Leave out the repeat, inc and until. They are not needed. Just have the for loop.
The for loop sets i to 0, then runs the code, increases i, runs the code again, until i is 39. when i is 39, it runs the code for the last time, before continuing with the program.
Dont know if that'll fix the access violation
Somebody
18-07-2009, 06:13 PM
Doesn't fix the violation. I have been playing around with it all day but nothing seems to work.
dislekcia
18-07-2009, 07:16 PM
Sounds like your array is too small and that's causing the access violation. I'm not up to speed on Pascal-style syntax, so I have no idea how large an array created that particular way is. Try setting your array to go from 0..40 or only iterate 38 times on i.
If that doesn't help, then you need to explicitly create the Tlabel's that make up that array if your compiler isn't creating them for you. Actually, this is probably the issue: You've allocated the space for all those labels, but they don't exist there yet, so you're getting access violations when you ask for specific info off something that doesn't exist ;)
The Dash
18-07-2009, 07:53 PM
If that doesn't help, then you need to explicitly create the Tlabel's that make up that array if your compiler isn't creating them for you. Actually, this is probably the issue: You've allocated the space for all those labels, but they don't exist there yet, so you're getting access violations when you ask for specific info off something that doesn't exist ;)
Delphi creates it automatically. Well, it should :p
Step through it and see where the error is? (F7)
Although i have to agree with Dis, my suspect would be the loop
Somebody
18-07-2009, 08:55 PM
Thanks alot! The array was too long is there something else I can use instead?
dislekcia
18-07-2009, 11:49 PM
Thanks alot! The array was too long is there something else I can use instead?
Oh, right. Sounds like you're not using extended memory... Um. I didn't realise you still had to care about that?
Somebody
19-07-2009, 12:43 AM
Oh, right. Sounds like you're not using extended memory... Um. I didn't realise you still had to care about that?
I have no idea what you are talking about since I had no idea there was even an array untill yesterday. But nevermind I found a way past it.
01DT!m3r
19-07-2009, 10:37 AM
@somebody, the reason its crashing is because you are creating an infinite repeat loop . I'll explain:your for-loop is assigning values to all the arrays and it sets i to 39(when the loop ends)you are then incrementing it to 40.Because you are checking to see if i = 39,which it will never be (it is always = 40).The solution:like the dash said ,get rid of the repeat loop(and the increment) and you won't get an error.Hope this helps .
dislekcia
19-07-2009, 07:20 PM
@somebody, the reason its crashing is because you are creating an infinite repeat loop . I'll explain:your for-loop is assigning values to all the arrays and it sets i to 39(when the loop ends)you are then incrementing it to 40.Because you are checking to see if i = 39,which it will never be (it is always = 40).The solution:like the dash said ,get rid of the repeat loop(and the increment) and you won't get an error.Hope this helps .
If you read above you'll see that he removed the inc and repeat-until earlier, which didn't solve the problem. If he was getting an infinite loop, he'd be getting a stack overflow error as the stack ran out of space to store things, not an access violation :)
Fengol
20-07-2009, 01:41 PM
I'm learning to use the GM particle system. I've built a little platformer where the player moves a character left and right and can jump onto platforms and stuff. I want to make little hearts appear above the characters head when he gets close to a power up but what's happening is that the hearts start to display when the character first comes into range, but as the character continues to move, the hearts continue to appear in the first position and not moving with the character.
Must I call part_emitter_region every time the player moves?
Fruzz
04-08-2009, 05:24 PM
Hey guys, I'm trying to work out how to get finite state machines working in game maker. Can I just use the normal point and click interface and build up some case statements on an object or is it better to use the scripting to do something like that? Has anyone done anything like that in Game Maker or know of a good place to do some reading up?
Thanks.
dislekcia
04-08-2009, 05:38 PM
Hey guys, I'm trying to work out how to get finite state machines working in game maker. Can I just use the normal point and click interface and build up some case statements on an object or is it better to use the scripting to do something like that? Has anyone done anything like that in Game Maker or know of a good place to do some reading up?
Thanks.
FSM's rely on a single variable that tells you which state an object is in and then very controlled and gated switching of that state.
You could use drag and drop elements to build case statements that check a single variable, or you could write code to do the same sort of thing. In the end it's the same thing, comes down to which you prefer.
OR (and this is the rad part)
You could use GM's instance_change() function to swap between mutiple different objects that are each a single state of your FSM. That way your code can be done any way you want in any events you want and you simply use instance_change() as your gated state change. GM's rad like that :)
Fruzz
04-08-2009, 06:27 PM
Oh awesome, thanks Dis, I'll have a look it this evening :)
Squid
15-08-2009, 11:34 PM
I have an issue and I think the problem is with how GM handles recursion and variables in memory. I'm pretty sure I have the logic fine.
I have an integer grid, containing mostly 0s some 1s and a 2.
eg.
0000000000000
0001000010000
0001010010000
0000000010000
0000100011111
0010001000000
0010001000200
0000001000000
What I'm trying to do, is calculate late whether there is a possible path of 0s past the 1s all the way to the 2. Naturally, given a starting point. (Let's say 0,0). The grid is a 50x50.
Here is the ExpandGrid method that I'm using to do it.
var sx;
sx=argument0;
var sy;
sy=argument1;
if (clearpathgrid[sx,sy] == 2) {
clearpath=true;
}else{
if (clearpathgrid[sx,sy] == 0) {
clearpathgrid[sx,sy] = 1;
if (sx > 0) {
ExpandGrid(sx - 1, sy);
}
if (sx < 49) {
ExpandGrid(sx + 1, sy);
}
if (sy > 0) {
ExpandGrid(sx, sy - 1);
}
if (sy < 49) {
ExpandGrid(sx, sy + 1);
}
}
}
Problem is, when I run this the game just hangs. The only explanation I can come up with is that clearpathgrid is not being updated correctly, hence infinite loop.
dislekcia
16-08-2009, 05:33 AM
[QUOTE=Squid;229050]I have an issue and I think the problem is with how GM handles recursion and variables in memory. I'm pretty sure I have the logic fine.
I have an integer grid, containing mostly 0s some 1s and a 2.
eg.
0000000000000
0001000010000
0001010010000
0000000010000
0000100011111
0010001000000
0010001000200
0000001000000
What I'm trying to do, is calculate late whether there is a possible path of 0s past the 1s all the way to the 2. Naturally, given a starting point. (Let's say 0,0). The grid is a 50x50.
Here is the ExpandGrid method that I'm using to do it.
var sx;
sx=argument0;
var sy;
sy=argument1;
if (clearpathgrid[sx,sy] == 2) {
clearpath=true;
}else{
if (clearpathgrid[sx,sy] == 0) {
clearpathgrid[sx,sy] = 1;
if (sx > 0) {
ExpandGrid(sx - 1, sy);
}
if (sx < 49) {
ExpandGrid(sx + 1, sy);
}
if (sy > 0) {
ExpandGrid(sx, sy - 1);
}
if (sy < 49) {
ExpandGrid(sx, sy + 1);
}
}
}
Your stack is probably overflowing. It feels like there are some situations that would lead to infinite loops in your code, but I think it's the fact that you keep checking in directions that you've checked before that probably overflows the code.
Firstly, why aren't you doing recursion right and returning a value that your calling function uses to make decisions?
And secondly, I think this isn't a good way to search for a path at all because it doesn't give you the option of backtracking correctly - your side-effects of setting things to 1 on visit means you can't really go back to previous grid states. I really think you should read up on rudimentary A* search methods in order to drastically reduce the number of checks you end up doing.
What's wrong with GM's built in pathfinding? Also, are you doing anything like looping on this until clearpath is true?
Squid
16-08-2009, 01:46 PM
Your stack is probably overflowing. It feels like there are some situations that would lead to infinite loops in your code, but I think it's the fact that you keep checking in directions that you've checked before that probably overflows the code.
Yar, I thought it was some kind of memory issue. I can't find anyway that it could get into an infinite loop.
Firstly, why aren't you doing recursion right and returning a value that your calling function uses to make decisions?
Err, um... I...
And secondly, I think this isn't a good way to search for a path at all because it doesn't give you the option of backtracking correctly - your side-effects of setting things to 1 on visit means you can't really go back to previous grid states. I really think you should read up on rudimentary A* search methods in order to drastically reduce the number of checks you end up doing.
A* is what I tried first, it didn't work out. So I just stole this code from a project of mine from a few years ago.
What's wrong with GM's built in pathfinding? Also, are you doing anything like looping on this until clearpath is true?
I always thought mp_grid_path just returned a path (or a straight line if no clear path existed). But, on closer inspection of help files, it appears that it actually returns whether or not a path exists. Sweet. Thank God for GM.
Nandrew
18-08-2009, 05:49 PM
I know that the above code has been discussed already, but I'd also like to point out that the problem may well lie with clearpathgrid and clearpath. These variables have a rather uncertain scope, and Game Maker can be really ****ing weird when you try using recursion with these buggers.
The problem would probably be sidestepped by making those variables global.
This By-now Completely Obsolete Solution brought to you by NandrewCorps™.
dislekcia
18-08-2009, 06:34 PM
I know that the above code has been discussed already, but I'd also like to point out that the problem may well lie with clearpathgrid and clearpath. These variables have a rather uncertain scope, and Game Maker can be really ****ing weird when you try using recursion with these buggers.
The problem would probably be sidestepped by making those variables global.
Probably not, actually. GM will stop executing when it detects that a script is being entered repeatedly and not really exiting. Because this particular script doesn't return anything and has very few guard statements to stop it from branching into itself multiple times. 50 * 50 is quite a large array, which is then leafed through 4 times extra.
I'm not surprised GM's going argh. Interpreted scripting systems tend to not have much stack space to work with anyway...
If you really had to use a script like that do 2 things: 1, never use global variables and recursion, always return the value you care about and have it bubble up; 2, make sure you do as much testing in a single call of the function as possible - don't have dead-case calls that return nothing without any logic really going on - that will save you stack space.
Nandrew
18-08-2009, 08:15 PM
I suppose I just mentioned that because I've just solved a similar self-calling script problem in the same way. Not for pathfinding or anything, though, so perhaps my method works in some arcane way that will break if I decide to change anything.
Now I feel all apprehensive and stuff. :<
The Dash
19-08-2009, 05:32 PM
Quick question, well two questions,
I suspect ds_grid_shuffle(id) changes the order of all the cells in a grid, is this true? (IE-It randomizes the positions of the x and y of a value)
So i want to use a map, as i only want two values (EG Playing cards- a suit and a number), unfortunately maps dont have shuffle (but lists and grids do)
Is there some coding ninja way to easily shuffle the values?
SkinkLizzard
19-08-2009, 06:28 PM
to be honest I don't think a map is the greatest idea in terms of your example of playing cards.
you'd need a key and a value, and regardless of whether you set the suit or the number as the key
you'd have duplicate keys overwriting each other. You'd have either 4 random number cards one in each suit or 13 cards
all with random suit, you could make it 52 cards with keys 1 - 13 being assigned one value, 14 - 27 being assigned another value and so on but its somewhat cumbersome imo.
also there's no real need to shuffle a map, the values are called by referencing the key. If you have to use a map and want random values from it, shuffle a list of keys and then grab the associating key value pair from the map sequentially using the shuffled list of keys as reference.
dislekcia
20-08-2009, 12:35 AM
Quick question, well two questions,
I suspect ds_grid_shuffle(id) changes the order of all the cells in a grid, is this true? (IE-It randomizes the positions of the x and y of a value)
So i want to use a map, as i only want two values (EG Playing cards- a suit and a number), unfortunately maps dont have shuffle (but lists and grids do)
Is there some coding ninja way to easily shuffle the values?
Ok, couple of logical things here:
1. A map isn't designed to store multiple values per object, it's designed to relate two otherwise unrelated things. For instance, if you wanted to store mail addresses for people's names and people could move to different addresses, then those two sets of data could be related by a map. Map[Name] = address.
2. Don't get confused by illusory data and patterns. A set of playing cards has 52 cards, each unique. You may get the 5 of clubs and the 5 of hearts, but those aren't the same card with different states, they're different cards ALL the time. That means that you can store a set of cards as strings: C1 (Ace of clubs), H5 (5 of hearts), D11 (Queen of diamonds). Meaning you can use a list to store them, which - conveniently - has a shuffle method :)
FYI: Because each card could be represented by a single object, you could always have used a list, even if you had really strange cards that had multiple possible identities ;)
The Dash
21-08-2009, 09:02 PM
FYI: Because each card could be represented by a single object, you could always have used a list, even if you had really strange cards that had multiple possible identities ;)
WIN
*Smacks forehead*
Next problem
Game is failing to connect over the internet, now i have no clue what the problem is.
Tried disabling firewalls, anti viruses etc. Still nothing. My pc doesn't reply to a ping either (Request timed out) (Actually, this should be in technology section)
If you feel like helping me out and just doing a quick test, you can get it here-
here (http://www.box.net/shared/9fp4qlhmsq)
Press connect, enter partners IP address, then they do the same once you are both connected, host must press deal, then the partner must press deal. Check that the cards are the same on both pc's
Unfortunately that's the furthest I've gotten. If you can test this for me, i will be greatly appreciative. And dont worry, if i can get it far enough along, ill post the rules ;)
Oh yes, pressing d brings up basic multiplayer information, pressing s saves this
EDIT:
http://www.whatsmyip.org/
Can be very helpful
Bonezmann
26-08-2009, 03:49 PM
Hi there, I have a top-down level design with a long wall. On the one side of the wall is the gaurd and on the other side is the alarm. Once the alarm is triggered it creates an object that expands(this emulates the sound waves). Now if the gaurd collides with this emulated sound object it should go to the alarm, which it does. However, when the wall is too long it spins around and walks toward the wall and then away from the wall the whole time. I'm using the step towards alarm1.x alarm1.y drag and drop button.
Any pointers on how to make the gaurd move around the wall, no matter how long it is towards the alarm?
Nandrew
26-08-2009, 05:42 PM
I think for proper pathing in GM, you're going to have to dig into scripts. There was discussion just a little earlier in this thread about pathing code, that would probably be useful to look up.
Bonezmann
26-08-2009, 05:53 PM
Thanx Nandrew, i'll look it up. :)
Evolution
26-08-2009, 10:11 PM
This question does not relate to Game Maker.
How do you make a C++ program link to a website using native code(no frameworks or dynamic link libries)?
Edit: never mind, I figured it out
Fruzz
26-08-2009, 10:20 PM
Hey guys,
I have three buttons, one for each of the fighting stances in my game. When I click one I want them all to have a cooldown time.
I have made three objects which are my buttons, how do I link my button objects so that on the mouse click event for one of them they all go into a cooldown?
Thanks.
Nandrew
26-08-2009, 11:05 PM
If you make sure that the buttons all inherit from a particular parent object, you could refer to changing a "cooldown" variable in the parent which *should* affect its children.
Something along the lines of
with (ParentObjectType)
{
cooldown=blah;
}
I thinkie that workie?
Fruzz
27-08-2009, 09:55 AM
Oh cool, thanks Nandrew. I was thinking about using inheritence but wasn't sure what to do with it. I'll try it out this evening.
Squid
02-09-2009, 11:19 AM
So I've finally decided to catch up with the times and start dabbling in XNA. So I install Visual Studio and Game Studio and create my first project.
buuuuuut... it won't run. The standard Game1.cs file just crashes with "The application was unable to start correctly" :(
I have a sneaking suspicion that Windows 7 may be behind this. Any ideas?
It might be best to look on the xna forums (forums.xna.com) I dont know if theyve found a solution for the windows 7 issues
CiNiMoDZA
03-09-2009, 08:24 PM
Im busy making a network game and Ive run into a problem. Im not that good at network coding! Ive got the game working with seeing each other and all that stuff, but now I need to make it that when athe player left clicks it creates a bullet at that point. It wont move, it will just appear there and then after 1 step it will disappear. the problem I have is that there can be an unlimted amount of bullets! There is only one bullet object, i you click on yourself you'll shoot yourself so you dont have to worry about multiple objects!!
EDIT-- Ok, insomniac helped me out a bit! Have I done this right, and if for arguments sake I had 30 people all doing this at the same time, would it still work??
When creating the bullet i say:
In global left lick
//--Create a bullet over the network
val = mplay_data_read(1000) + 1
mplay_data_write(1000, val)
mplay_message_send(0, val, string(mouse_x + accuracy)+','+string(mouse_y + accuracy))
and then in my step event
if (mplay_message_receive(0) > 0)
{
mes = mplay_message_value()
mesno = string_length(mes)
compos = string_pos(',', mes)
xval = real(string_copy(mes, 1, compos - 1))
yval = real(string_copy(mes, compos + 1, mesno))
{
instance_create(xval, yval, Bullet)
}
}
It seems to work fine with just 2 players, would this work with quite a few??
dislekcia
04-09-2009, 02:29 AM
What you've written there will create a bullet every time any player clicks. However, bullets might get lost if more than one message arrives in a single step (use a while loop to deal with that) and you're not exactly coding for multiple situations here: Every message that comes in is treated like it's a bullet.
Also, what's with the mplay_data_read and write stuff? That's one way of sending data over a network, mplay_message_send() is another. They both work differently. So far, you're not doing anything with that value stored in data slot 1000, the message receiver isn't using the message id at all...
There are 3 classic problems in networking:
1. Timing - how do you know when something arrived and when it was created? In your game, you're assuming that every player is going to get the message at the same time and that they're all running the same frames per second. This is naive. What if one player gets a bullet message 0.1 of a second after another player gets it, meaning that he now gets hit by the bullet, when it would have missed him before. How does the game deal with that?
2. Identification - how do you know who created which bullet? How will you have multiple types of messages, like when you want players to move. How will you know WHICH player is moving when those messages arrive?
3. Determinism - how do you ensure that the same thing happens on all the connected PCs and that it will always happen the same way, given the same messages?
Squid
04-09-2009, 10:51 AM
Also. dislekcia has a pretty damn awesome networking framework built in GM. Anyone have the link? I can't upload :(
dislekcia
04-09-2009, 11:24 AM
Also. dislekcia has a pretty damn awesome networking framework built in GM. Anyone have the link? I can't upload :(
El frameworko (http://www.gamedotdev.co.za/files/GM_Networking_Framework.zip), hope it's not too confusing. Included the networking presentation I give pretty much everywhere and the examples we came up with over the DevLAN to fix people's problems.
CiNiMoDZA
04-09-2009, 10:30 PM
Do you have a proper tutorial for that famework?? Im pretty new to networking?!? It would have to be a really basic tutorial, I dont understand anything about networking :P Does anyone know where I can find one??
dislekcia
05-09-2009, 02:33 AM
Do you have a proper tutorial for that famework?? Im pretty new to networking?!? It would have to be a really basic tutorial, I dont understand anything about networking :P Does anyone know where I can find one??
The framework was based on this explanation of the networking in Unreal (http://unreal.epicgames.com/Network.htm). Unfortunately I don't have any tutorials about the framework, it's pretty straightforward though: ReplicatedObj is the key to everything, Server and ClientObj handle their respective message passing to the things that implement replicatedObj correctly. All you really need to do is spend some time messing with those three and following how their scripts work and it should become clear.
Chippit
05-09-2009, 11:50 AM
The framework was based on this explanation of the networking in Unreal (http://unreal.epicgames.com/Network.htm). Unfortunately I don't have any tutorials about the framework, it's pretty straightforward though: ReplicatedObj is the key to everything, Server and ClientObj handle their respective message passing to the things that implement replicatedObj correctly. All you really need to do is spend some time messing with those three and following how their scripts work and it should become clear.
Similarly, Valve have a really nice resource on the way their networking model works in Source, with particular focus on TF2. Their model is based on that used in Unreal, but slightly modified in terms of their prediction systems.
These (http://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking) two (http://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization) pages do a pretty good job of explaining what's going on, with a bit of a more practical focus in comparison to Sweeney's doc.
Admittedly, I haven't seen dis's framework, so chances are this page might not help you understand what's going on there, but it almost certainly will help you get to grips with the general issues in network multiplayer and give you a headstart if you ever want to write your own system. ;)
CiNiMoDZA
10-09-2009, 09:54 PM
Im trying to make a lan game but would like it to be compatible for online play also. On the GMC forums they talk alot about this 39dll?!? Is it worth learning to use it??
dislekcia
10-09-2009, 11:11 PM
Im trying to make a lan game but would like it to be compatible for online play also. On the GMC forums they talk alot about this 39dll?!? Is it worth learning to use it??
No. A message passing DLL is not going to help you understand what to send to other games. Trust me.
CiNiMoDZA
11-09-2009, 11:49 AM
Why cant I connect to someone over the internet?? I can connect locally fine! Here is the source for my project! Ive tried to use comments as much as possible so that you can see what Im attempting :P Use right mouse button to move around!
Source: http://www.mediafire.com/?lyjmlhjehd2
Edit: Mouse movement has been removed due to some bugs, but thats not the focus now! Need to figure out how to connect!
Bonezmann
15-09-2009, 09:01 PM
If I'm not mistaken, you need to use TCP/IP to connect over the internet, haven't checked you source yet as I might not be too much help in the multiplayer department.
dislekcia
16-09-2009, 03:23 AM
Why cant I connect to someone over the internet?? I can connect locally fine! Here is the source for my project! Ive tried to use comments as much as possible so that you can see what Im attempting :P Use right mouse button to move around!
Source: http://www.mediafire.com/?lyjmlhjehd2
Edit: Mouse movement has been removed due to some bugs, but thats not the focus now! Need to figure out how to connect!
Are you port-forwarding traffic to your router to your PC's internal network IP on port 31337? Are your firewalls set to allow that traffic (on both sides)? Are the clients trying to connect to you using your internal network IP or the IP assigned to your router by your ISP? They should be using the latter.
CiNiMoDZA
16-09-2009, 08:06 PM
Ill keep testing my program and when Im happy Ill try again! thanks Dis. Now another question. While making the framework for a game(an MMO, just to try it), I see that each player in the game only sends 2 bytes of data evertime they move. Then why do we get pings of like 300 if its only 2 bytes of data??
dislekcia
17-09-2009, 12:28 AM
Ill keep testing my program and when Im happy Ill try again! thanks Dis. Now another question. While making the framework for a game(an MMO, just to try it), I see that each player in the game only sends 2 bytes of data evertime they move. Then why do we get pings of like 300 if its only 2 bytes of data??
So... Did anything suggested actually help? You haven't said either way.
Your ping has nothing to do with how much data you send, unless you send enough data to flood any point of the connection between you and your server and cause packet loss. Your ping is the measurement of how long it takes a single packet to get from your machine to the intended recipient and back. That's all. The size of that packet doesn't matter.
Obviously you don't want to be sending packets of 2 bytes all the time because the TCP header on that packet is much, much bigger than that. Not great use of bandwidth there. (Plus your code sends 1 byte, 1 byte, 16 bits and another 16 bits, that's 6 bytes)
CiNiMoDZA
20-09-2009, 02:24 PM
I tested my program on a friends PC and it worked fine! Apparently these damn routers are buggy when it comes to port forwarding! Its the Telkom 105WR! But my code is all fine I think!!
DukeOFprunes
25-09-2009, 01:48 PM
The internet says "you can't lol", but maybe one of you orrible lot found a simple way: how do you get the size of an array?
Nandrew
25-09-2009, 02:15 PM
You can use 1- and 2-dimensional arrays in GML. Simply put the index between square brackets for a 1-dimensional array, and the two indices with a comma between them for 2-dimensional arrays. At the moment you use an index the array is generated. Each array runs from index 0. So be careful with using large indices because memory for a large array will be reserved. Never use negative indices. The system puts a limit of 32000 on each index and 1000000 on the total size. So for example you can write the following
As far as I know, the size of the array is basically equal to the size of the highest index value you've specified. On da fly and all that. I don't know of any commands to explicitly find the highest known index, but I'm sure you could create some sort of flagged variable to do that for you as you go along. :)
DukeOFprunes
25-09-2009, 02:30 PM
Ok, here (http://mysite.mweb.co.za/residents/furp/GM/asteroids.gmk) is something puzzling me.
I'm building an Asteroids clone to learn GM. To explore the way it works with variables and scripts, I've decided against using the built-in x, y, speed and direction variables for the ship, and instead declared my own in the Create event.
Thus, in the step event, I use Sin and Cos to figure out where it should be based on its rotation (in degrees) and current speed. The same code works fine if not using GM.
As you can see from running the included source, it only seems to rotate between 8 different angles, but you can see its current heading/rotation and that it should not give you those results.
I suspect I shouldn't be using the Step event?
So, uh, HALP!1
SkinkLizzard
25-09-2009, 02:39 PM
sin and cos work on radians in gm, so 0 to 2 pi.
as far as I can see you're using degrees
DukeOFprunes
25-09-2009, 02:44 PM
sin and cos work on radians in gm, so 0 to 2 pi.
as far as I can see you're using degrees
LEVEL UP!
I wrapped rotation in degtorad(), now it's working. Mucho gracias!
herman.tulleken
28-09-2009, 12:10 PM
Hi all,
I am struggling with a rather ridiculous problem: How do you set title bar text? (No help from Google, the help file, or my memory [pretty sure I have done it before]).
Thanks,
ht
Gazza_N
28-09-2009, 12:20 PM
Ergh. I don't have GM here at the moment to double-check, but don't you set it in your room properties in the "room caption" field? Alternately, I'm sure there's a window_title or window_caption property lying in there somewhere that you can set using scripts.
herman.tulleken
28-09-2009, 12:22 PM
Of course!
Thanks a lot!
ht
The Dash
28-09-2009, 01:28 PM
Hi all,
I am struggling with a rather ridiculous problem: How do you set title bar text? (No help from Google, the help file, or my memory [pretty sure I have done it before]).
Thanks,
ht
Rooms have a number of additional properties:
room_width* Width of the room in pixels.
room_height* Height of the room in pixels.
room_caption Caption string for the room that is displayed in the caption of the window.
room_persistent Whether the current room is persistent.
Alternatively, Go to your room->settings and enter the caption in there
herman.tulleken
28-09-2009, 02:07 PM
Thanks Dash - I missed it because I was searching for title related stuff (title bar, title text, etc.) The room caption works perfectly.
ht
CiNiMoDZA
06-12-2009, 10:11 PM
Hey, I need some help with a zombie survival game Im making! I have this really basic movement system, but now i want my little man to strafe when I push A and D! Please can someone help! I thinks trig is gonna be involved??
Simple Movement DL(GM7): http://www.mediafire.com/?jok2eiwlmya
Nvm, I got it to work! Thanks to gml's lengthdir_x and y!!
Bonezmann
07-12-2009, 11:26 PM
Hi there, sorry if this is a tad of a stupid question, but how do I change the object the room should follow mid-game? Any pointers?
edit: iow, I have the room follow obj_player, now I want to change it to follow obj_bird when obj_player collides with a certain power-up.
Thanx in advance. :)
SkinkLizzard
08-12-2009, 12:43 AM
view_object = obj_bird
should work for the current room if it doesn't then
use view_object[#] = obj_bird, where # is the number of the room the player is in.
dislekcia
08-12-2009, 01:28 AM
use view_object[#] = obj_bird, where # is the number of the room the player is in.
Nope, where # is the number of the currently active view in GM.
Bonezmann
08-12-2009, 07:37 AM
Awesome! Thanx a lot! \o/
CiNiMoDZA
09-12-2009, 10:30 AM
How do I "draw" a triangle in front of an enemy object(that moves around), that, when the player object is within that triangle, the enemy object can see the player?? If that makes sense!
SkinkLizzard
09-12-2009, 02:09 PM
there may be other ways of doing this but you could use point direction and point distance to get the
players position from the enemy and check manually if its inside the see-able range
otherwise you could use a somewhat hack method of making a sprite the shape and size of the enemies sight(origin at the apex)
make an object called enemy_see, give it your triangle sprite, uncheck visible and
in the create event of the enemy_see object create a variable called host.
whenever you create an enemy you create one of these enemy_see objects and assign its host variable to the instance id of the enemy you just created.
in the step event of the enemy_see object you can assign its direction to host.direction and its x and y to host.x host.y this will keep the sight triangle attached to the enemy.
in the enemy_see collision with player event you can handle alerting the enemy by saying
host.can_see = true or something similar.
just remember you might want to store the enemy_see instance id inside its host enemy as well so that when you kill the enemy you can destroy the sight triangle too.
CiNiMoDZA
09-12-2009, 07:03 PM
Ja, I know that way, but it wont work too well! Ive got (literally) 1000 enemies moving around on the screen! I want it to be as system light as possible!! I have already used that method!
SkinkLizzard
09-12-2009, 07:18 PM
having a sight object is probably the system lightest method( I may be wrong )
if you're really worried you can disable the sight triangle when the enemy is outside of a certain range from the player this cuts down the number of sight objects running.
to be honest I don't see how 1000 enemies that use an object for range/sight finding would slow up your system, the triangle does very little calculation.
CiNiMoDZA
09-12-2009, 07:58 PM
Hmm, ok!! Ill do it!!! I just thought that now I would have 2000 objects instead if just 1000! Cool beans! Ill have something to post on the mor?!!
SkinkLizzard
09-12-2009, 10:30 PM
your worries inspired me to test it, and once I tested I got carried away
http://www.box.net/shared/utr5k5zl7b
requires gm7 pro
Fps, enemy count and enemies that can see the character are shown in the window caption
CiNiMoDZA
10-12-2009, 11:47 PM
So my code is pretty much done! I have a counter which counts down(Ill explain why I need this later!) I have my zombies running around mindlessly until they see you! A gun, and a baseball bat! My room speed is set to 60, but as soon as I add more than 40 zombies, the FPS's begin to drop! I tried moving all my if statements into a switc(yes I know, probably uber noob of me :P), I tried disabling the vision?? I just dunno what to do! Is there anything I can do, or am I going to have to just base my game around less but stronger zombies??
Source (http://www.mediafire.com/?3u3myzowmiy) 300kb
The Dash
15-12-2009, 11:28 AM
Can anyone please spot a problem with this code?
GRID_WIDTH=ds_grid_width(GRID)
GRID_HEIGHT=ds_grid_height(GRID)
temp_surf=surface_create(GRID_WIDTH*75,GRID_HEIGHT *75)
surface_set_target(temp_surf)
draw_rectangle(0,0,GRID_WIDTH*75,GRID_HEIGHT*75,fa lse)
temp_spr=sprite_create_from_surface(temp_surf,0,0, GRID_WIDTH*75,GRID_HEIGHT*75,false,false,false,fal se,0,0)
sprite_index=temp_spr
surface_reset_target()
Right, so whats going on is that i have a grid drawn that gets clicked on, and this grid grows and shrinks. When the grid changes size the area that can be clicked on changes, so this is what the code is meant to do. It works fine in the create event, but when i increase the grid size the clickable area doesn't increase
EDIT: Nothing wrong with the code, but once i moved it out of the object and into a script it worked fine, which is strange considering it works in the create event of the object
The Dash
16-12-2009, 10:29 AM
Okay new question,
I have several objects that act as walls, each has their parent set to a parent wall object, ie:
object_set_parent(oID,parent_unit_wall)
Now how would i find the closest wall to a point? Using
furthest_wall=instance_furthest((GRID_WIDTH/2)*75,GRID_HEIGHT*75,parent_unit_wall)
just doesn't work, and i have no idea how to do it without drastically increasing my code, which is what i hoped to avoid with using parents
SkinkLizzard
16-12-2009, 10:51 AM
instance_nearest ?
The Dash
16-12-2009, 06:48 PM
instance_nearest ?
No, the furthest instance from this side of the board is the nearest to the other side.
The problem is that it returns noone (-4) when i run the code
dislekcia
19-12-2009, 02:30 AM
You weren't re-creating the surface and sprite when your grid changed size. The calculation that allowed clicking was only happening in your create event which is only called once per instance of an object. If your grid changed size dynamically, then you need to re-run that specific code, which is probably why it worked when you made it a script (ie: You changed it to run every frame or something - coincidentally, having it run every frame when the grid HASN'T changed size isn't exactly super-efficient).
Okay new question,
I have several objects that act as walls, each has their parent set to a parent wall object, ie:
object_set_parent(oID,parent_unit_wall)
Now how would i find the closest wall to a point? Using
furthest_wall=instance_furthest((GRID_WIDTH/2)*75,GRID_HEIGHT*75,parent_unit_wall)
just doesn't work, and i have no idea how to do it without drastically increasing my code, which is what i hoped to avoid with using parents
I think you're not understanding how parenting works in GM and what it's for. Parents are a way of creating object types that can extend beyond single instances. If you would create a basic Wall object and then special sorts of wall objects, like PushableWall and DestructableWall, then you'd set those two objects' parent attribute to Wall to allow collision events (and the like) that target Wall to work with those as well.
What is it that you're trying to do? Explain it in detail so that we can couch what you're aiming at into GM-friendly implementation :) Although, from the sounds of it, instance_nearest really IS your best bet, provided you do parenting right.
The Dash
20-12-2009, 12:48 PM
You weren't re-creating the surface and sprite when your grid changed size. The calculation that allowed clicking was only happening in your create event which is only called once per instance of an object. If your grid changed size dynamically, then you need to re-run that specific code, which is probably why it worked when you made it a script (ie: You changed it to run every frame or something - coincidentally, having it run every frame when the grid HASN'T changed size isn't exactly super-efficient).
The thing is it was in a user defined event (User Defined 0). The create event called this, and when the grid changed size it was called again, the create event call ran the code fine, but not when i called it later. i just replaced the event with a script and it works fine, i dont know why, just GM not liking me again :(
I think you're not understanding how parenting works in GM and what it's for. Parents are a way of creating object types that can extend beyond single instances. If you would create a basic Wall object and then special sorts of wall objects, like PushableWall and DestructableWall, then you'd set those two objects' parent attribute to Wall to allow collision events (and the like) that target Wall to work with those as well.
What is it that you're trying to do? Explain it in detail so that we can couch what you're aiming at into GM-friendly implementation :) Although, from the sounds of it, instance_nearest really IS your best bet, provided you do parenting right.
Parenting didn't work (Apparently, you cant create multiple instances of the same object, but with different parents set at run time (Because once you change the parent for one, it changes it for all instances of that object, i thought it was the same principle as the solid property))
So i added a few more variables and wrote a custom instance_nearest script.
The problem was thus: (for interests sake)
I have only one object that is on the grid, but it can be a players unit, a zombie, or a wall. I needed to find the closest zombie to give it more move points (to get to the other side fastest), the furthest zombie to give it more health (because its the one most likely to have taken damage), and the closest wall, so it can be destroyed (zombies have a card to do this)
I was trying to use parents, then simply use instance_nearest(parent) to get the closest wall or zombie or whatever, except the parent system wasn't working. So i grabbed an extension off the net (Instance Nearest Extended), but that had too many bugs to work effectively (Although it has a 9/10 rating from over 100 votes). So i basically rewrote his code to suit my needs and came up with: (Not very efficient but it works)
//instance_xth_nearest( type of object ; x ; y ;nearest or furthest)
globalvar _array;
var _no_of, vmin, vmax;
_array=ds_priority_create()
_no_of=instance_number(object_on_grid)
if _no_of>0 then //if there are objects on the grid
begin
with (object_on_grid)
if type=argument0 then //if they are the right type (player, zombie, wall), then add them to the array
begin
ds_priority_add(_array, id, distance_to_point(argument1,argument2))
end
vmin=ds_priority_find_min(_array) //closest object to the point
vmax=ds_priority_find_max(_array) //furthest object to the point
ds_priority_destroy(_array) //free the memory
if argument3=0 then
return vmin
else
return vmax
end
else //if there are no objects on the grid, script failed to run. return -1
return -1
dislekcia
20-12-2009, 01:53 PM
Quick question: What was stopping you having object_on_grid be an instance type and then creating 3 new instance types that all inherited from object_on_grid? You'd end up with zombie_on_grid, wall_on_grid and player_on_grid (or, y'know whatever you called them), each type's parent set to object_on_grid. Then you could call instance_nearest(zombie_on_grid) and get the nearest zombie, or instance_nearest(object_on_grid) and get the nearest zombie, player or wall.
The Dash
20-12-2009, 06:51 PM
Quick question: What was stopping you having object_on_grid be an instance type and then creating 3 new instance types that all inherited from object_on_grid? You'd end up with zombie_on_grid, wall_on_grid and player_on_grid (or, y'know whatever you called them), each type's parent set to object_on_grid. Then you could call instance_nearest(zombie_on_grid) and get the nearest zombie, or instance_nearest(object_on_grid) and get the nearest zombie, player or wall.
0.0
Good thing its too late to implement it =P
faultyit
27-12-2009, 01:57 PM
Wanted to get into creating games since the first time I touched a Pc(+-12years ago) even took IT. in the hopes of finding a good platform to create games...only found untold misery... What platform should I start with? Are there any freeware platforms that I can download? What is game.dev??? Remembered the one game that won the game.dev competition and that was on a nag disc a while back:Fastfood in space...so simple yet so addictive... please want to get into the scene tired of sitting back :((
Graal
27-12-2009, 02:30 PM
Most games here are created with Gamemaker, which is a reasonably easy to use program and if I remember correctly, free. For the more advanced stuff you're going to need to know a bit more about programming, though. Not sure how it compares to Java programming, though. There should be quite a few tutorials around here.That's where I fall off the bus. As for game.dev, it's both an electronic magazine as well as a competetion. You basically get 4(or 6, not sure) weeks to create a game, and them whoever has the best game wins a spot in the limelight as well as some free publicity.
Fengol
27-12-2009, 11:30 PM
@faultyit, I definitely recommend starting with GameMaker (http://www.yoyogames.com/gamemaker) (BTW, I see you now download version 8) and go through a couple of their tutorials. You can also post on the Game.Dev forum any questions you have. The community here encourages hobbyist game developers to enter and share their games with the community to provide feedback and suggestions. The community also runs Dev.Mag (http://www.devmag.org.za/) an online e-zine with local and indie news and game development articles.
faultyit
29-12-2009, 12:55 PM
Tnx alot! hehe catch the clown...
Fengol
30-12-2009, 07:50 PM
is it possible to get a value of a variable for an object, not an instance?
I've created an object Building and in the Create event I've put code "buildcost = 0;" and now in my menu, I want to be able to get the value of buildcost before I create an instance of Building.
I think this might be impossible because, of course, the Create event won't fire until I've actually created an instance of the object.
Should I maybe use RoomStart or GameStart? Would those events require an instance?
Fengol
30-12-2009, 07:58 PM
Nevermind. To answer my own question I was getting confused between an object and an instance and with the variables not being static I don't have access to them. I thought I was being clever by putting the variables relating to a building in the building, but that's like put the hammer in the crate and then trying to open the create with the hammer.
The Dash
30-12-2009, 08:30 PM
Nevermind. To answer my own question I was getting confused between an object and an instance and with the variables not being static I don't have access to them. I thought I was being clever by putting the variables relating to a building in the building, but that's like put the hammer in the crate and then trying to open the create with the hammer.
I suppose the values wont be static either? If they are static (IE A building will always cost the same) why not use a constant? (Global Game Settings->Constants)
Or what i sometimes do is have one persistent object with global variables that handles this kind of stuff
Fengol
30-12-2009, 08:34 PM
I'm doing something similar to your latter suggestion, the controller object I created to create buildings keeps the costs now
SplaT
04-01-2010, 12:26 PM
Can anyone give me some advice on creating a hud that sticks to the current view?
What I'm looking to make is a bar at one side of my screen that displayed objects that can be built on the map. At the moment it creates the objects inside that 'inventory' bar once the player has access to an object.
At the start of the game, it draws the HUD relative to the current view. But I don't know how to make the objects /stick/ to their place on that bar once the view moves.
Say the game gives the player Object 1 and it gets added to the inventory bar and the view moves, Object 1 stays where it is and thus moves off the screen.
I can't really set the x and y in the step event of Object 1, because then the object would become jittery when it moves with the HUD.
I also tried to draw the sprites of the objects, which solved the jitter problem, but I want the player to be able to have a click event on the objects in the HUD.
I have tried a couple of solutions, but all of them are very flimsy and feel very unstable.
Is there a way to get the HUD on a separate view from where it can be controlled then use it as an overlay, so that it has no effect on the underlying game. For example collision events that would occur if the character walks near the objects that is on the HUD. (If that makes sense.)
SkinkLizzard
04-01-2010, 01:19 PM
instead of having the hud made up of objects
have a single object that draws the hud, this will mean dealing with clicking
hud options yourself though.
I have a hud example somewhere here I'll find it and upload see if it helps
it may be like most of the others you've already tried though.
you can use 2 separate views in a single room at the same time I tried this back in comp 10
it somewhat messy though.
hud Example (http://www.box.net/shared/3iinc72eft)
The Dash
04-01-2010, 01:48 PM
What I'm looking to make is a bar at one side of my screen that displayed objects that can be built on the map. At the moment it creates the objects inside that 'inventory' bar once the player has access to an object.
At the start of the game, it draws the HUD relative to the current view. But I don't know how to make the objects /stick/ to their place on that bar once the view moves.
Say the game gives the player Object 1 and it gets added to the inventory bar and the view moves, Object 1 stays where it is and thus moves off the screen.
I can't really set the x and y in the step event of Object 1, because then the object would become jittery when it moves with the HUD.
I also tried to draw the sprites of the objects, which solved the jitter problem, but I want the player to be able to have a click event on the objects in the HUD.
)
Change the x and the y in the draw event, not the step event, that gets rid of the jittering. (Neat little trick i've learnt :p) It only really slows down the game once you put too many things in the draw event, or have too many objects. So dont use this method to populate a town or something
dislekcia
04-01-2010, 03:26 PM
When I need to have objects that are re-positioned according to a "root" object, I do something like this:
Create event:
anchorObject = -1;
offsetX = <number>;
offsetY = <number>;
Step event:
if (anchorObject > -1) {
x = anchorObject.x + offsetX;
y = anchorObject.y + offsetY;
}
Then, when I create the UI element, I just set it's anchorObject to point to the object it's supposed to use for positioning.
Also, the jittering you're talking about it due to ordering in GM. Basically, an object is being updated before some other object that it relies on. This means that it uses "old data" instead of "new data" that would be calculated this frame. The way to deal with this isn't to move the calculation to the draw event (because if you have a lot of objects all pulling data in a draw event, they could still execute in the wrong order) but to give objects the right depths. GM executes from greatest to least depth, so a root UI object should be "deeper" than an object that relies on it for positioning.
Fengol
04-01-2010, 03:59 PM
I have to agree with SkinkLizzard that, for War Machine, I had a single build menu object that drew and managed the things the player can build. Also while I moved the object in the step event, in the draw event I didn't use X, Y but instead used the view's coordinates and updated the boundary boxes for the items
Bonezmann
10-01-2010, 05:43 PM
Okay, I have an object I want to turn more B&W the lower its health goes. When at full health it should be in full color but when its health reaches zero it should be B&W. Now normally I'd just wangle something in the animation/subimage, link it to the health, but the trick is the object is animated already. Any pointers?
SkinkLizzard
10-01-2010, 06:53 PM
you could duplicate the sprite make the new one black and white then draw it over the other sprite
with alpha linked to health so 0 health corresponds to an alpha of 1
Bonezmann
10-01-2010, 07:00 PM
Would this work on a moving sprite? It's the player, I've done something with a portrait for now, until I've figured out how to do it with the player.
SkinkLizzard
10-01-2010, 08:24 PM
if the two sprites are identical (just ones B&W) and you draw the overlay with the exact same image_index as the player then yes it should work
Bonezmann
10-01-2010, 08:40 PM
Cool! Thanks SkinkLizzard!
Okay, new problem. The game is a platformer and I use tiles. My character gets stuck in walls sometimes, any help?
dislekcia
10-01-2010, 09:14 PM
Would this work on a moving sprite? It's the player, I've done something with a portrait for now, until I've figured out how to do it with the player.
There's no reason why it shouldn't. You're going to have to mess with your player object's draw event and spend some time looking up the drawing commands and variables (draw_sprite_ext(), image_angle, image_xscale and the like) but it'll work fine :)
SkinkLizzard
10-01-2010, 10:37 PM
Cool! Thanks SkinkLizzard!
Okay, new problem. The game is a platformer and I use tiles. My character gets stuck in walls sometimes, any help?
well when the player collides with a block (i'm assuming wall and floor blocks are the same object)
you can move the player object in the opposite direction
-point_direction(player.x,player.y,block.x,block.y)
until they no longer collide.
otherwise check one pixel ahead of the player in its current trajectory to see if it would collide
using place_meeting, then check whether the collision is above below left or right and act accordingly
Bonezmann
10-01-2010, 10:47 PM
Ooh, Thanks SkinkLizzard. I had an idea it would be something like that so I tried a few things but failed. I'll give that a whirl tomorrow.
@ Disleckia, I'll check out the draw commands and their variables too. It's about time I learn a bit more... :)
CiNiMoDZA
13-01-2010, 01:41 PM
Please can someone assist me! Im trying to make my own version of the old game The Clue. Im trying to replicate the planning system that they use when planning a robbery! Ive tried using paths but I think its too much work and there must be a simpler way! I think I need to use a timeline, but I just dont understand them? Any suggestions?
dislekcia
13-01-2010, 04:54 PM
Please can someone assist me! Im trying to make my own version of the old game The Clue. Im trying to replicate the planning system that they use when planning a robbery! Ive tried using paths but I think its too much work and there must be a simpler way! I think I need to use a timeline, but I just dont understand them? Any suggestions?
Sorry, haven't played the game you're trying to remake... Would you mind explaining what it is you're trying to do exactly?
CiNiMoDZA
13-01-2010, 11:54 PM
Ok, sorry. Let me clarify.
In the game The Clue, you plan robberies. You start off by selecting your accomplices, you can have up to 4. You start the plan and when ever you move your selected character the timer runs! Basically, I want to control one person at a time, once Ive done their moves in the plan I can switch to the next person. While controlling that person, I can see what I had all the people do, and the effects they had on the enviroment(open doors, crack a safe etc.) Let me know if I need to clarify anymore!
Powered by vBulletin® Version 4.2.4 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.