• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help with game code

M

Motivating

Guest
Hello everyone, i've been trying to figure out how I would go about coding this for my first game but I couldn't figure it out so I decided to see if anyone has the knowledge of how I would go about doing this on the forums. Pretty much I'm trying to figure out for my climbing game how I could increase the speed that the branches (objects) fall and spawn everytime 10 branches are passed. I will link a picture of my concept, any ideas?depiction.png
 
W

wagyu_so_gud

Guest
Think of it like this:

Each time a branch is destroyed (fallen outside of the room,or, if the y position of the branch is greater than the player's y position), have a variable that registers it. And once that branch variable is >= 10, reset it back to 0, and add the amount of speed you want (to the obj_branch's speed variable).
 
I

InkSho

Guest
if you have an object spawning the branches you can make that object count the number of times it does that an set variables for different alarms to accommodate different speeds
 
M

Motivating

Guest
I don't have an object counting the branches but I could make one. Would that be the best way to go? How would I make it register the number of branches that hit it? I have 2 object Rbranch and Lbranch so should I make 2 separate boxes? How would I code that
 
I

InkSho

Guest
uh alright just off the top of my head you could make an object called obj_spawner and just dump it somewhere in the room
also id say just make a single branch and make it flip if the x value goes beyond a certain point

then create event

alarm[0] = 1
gotsagofest = 0 //custom variable that counts the branches

alarm 0 event

if gotsagofest <= 4
{
instance_create(choose(wherever,wherever2),0,obj_branch)
gotsagofest += 1
alarm [0] = 20 // the lower the number the faster it goes
}

if gotsagofest >= 5
{
instance_create(choose(wherever,wherever2),0,obj_branch)
gotsagofest += 1
alarm [0] = 15 // the lower the number the faster it goes
}

etc...
 
M

Motivating

Guest
Don't know if I'm doing this correctly but here is what I'm doing atm, still getting errors unfortunatly Example1.png example2.png
 
Last edited by a moderator:

FrostyCat

Redemption Seeker
Why don't you read the Manual entry on alarm events and see for yourself? In this context, it is quite clearly the event that generates the branches --- the shorter the alarm interval, the more branches come out.

InkSho did make a rookie mistake, though --- imagine gotsagofest at 4 and see for yourself what the problem is. This is why skilled users frown upon similar if (condition) { ... } if (!condition) { ... } anti-patterns and use if-else instead:
Code:
if (gotsagofest <= 4) {
  instance_create(choose(wherever, wherever2), 0, obj_branch);
  gotsagofest += 1;
  alarm [0] = 20; // the lower the number the faster it goes
}
else {
  instance_create(choose(wherever, wherever2), 0, obj_branch);
  gotsagofest += 1;
  alarm [0] = 15; // the lower the number the faster it goes
}
 
I

InkSho

Guest
I just used multiple if statements in case he wanted to create more opportunities to shorten the alarm times
 
M

Motivating

Guest
Would I need an alarm if I would trigger it from a collision? Trying to learn but this is how I'm approaching it, don't know if I'm doing it correctlyExample3.png
 
I

InkSho

Guest
you need a create event for that custom variable, id say just shorten it down to something like "tree"
so in the create event just type tree = 0
 
M

Motivating

Guest
The branch scrolls down to hit the box to trigger this event to speed up the background and branch speed every 10-15 hits?
 
I

InkSho

Guest
what I gave you doesn't have to do with collision, it counts how many times it has spawned a branch and once the amount reaches a certain amount, it will automatically speed up
 
M

Motivating

Guest
Fixed the coordinates and used the object. I think I'm going to create 2 objects for each side. One for right branches and one for left branches. Here is what I have for the trigger object for left branchesExample4.png
 
M

Motivating

Guest
Ohhh ok, so would I just create custom code in an alarm? That works too
 
I

InkSho

Guest
I guess making a spawner for each is fine but it would just be a lot more simple if you had only a left branch and if x = 500 then image_xscale = -1, which would flip the image horizontally.
 
M

Motivating

Guest
Ok I think now I'm doing it correctly, the alarm is on my room, I'm getting an error but I don't see where the issue is Example5.png
 
M

Motivating

Guest
Figured it out, typo with alarm[0] = tree. Thanks for the help!
 
M

Motivating

Guest
The game runs but the code isn't working as intended. Here is my set up now. I have a collision event using another object and set it to Alarm 0 to spawn branches on a timer, would that have any impact if they're both alarm 0? Sorry for the noob questions

Notworking1.png Spawnr.png
 

Attachments

I

InkSho

Guest
the first two lines should be in the objects create event, not the alarm[0] event, then get rid of alarm[0] = tree, that doesn't mean anything. finally id say just keep the tree += 1 for now.
 
M

Motivating

Guest
Ok that worked but it looks like it increasing the spawn rate of the branches, i'm trying to increase the speed of the background and branches moving down the screen (the branches move with the background) to increase the speed for the # of branches spawned for ex. 10 left branches spawn, background speed is increased to 2 if 10 more spawn increase speed to 3 etc. It's a game to climb and avoid branches so I want it to give the perception that the character is moving faster up the tree as they get past more branches to make things more challenging =)
 
I

InkSho

Guest
ah that's gunna be a huge sync test of trial and error. you could make other objects worth similarly to the alarm you set up like the branches.

if triggerbranch_left.tree <= 4
{
vspeed = 1
}
else
{
vspeed = 2
}
 
M

Motivating

Guest
I tried it, not working =/. Here is the code set up and concept of what I want in the thumbnailsConcept.png Concept2.png
 
C

ConsolCWBY

Guest
Motivating, are you using 2 objects to create the branches? If so, use a global variable as a counter everytime you spawn a branch. Test the global variable in ONE SPOT ONLY - you choose the spot - and once that variable equals 10 (because 10 branches have been spawned), add a number to the speed while setting the global variable to 0. If you instead wish to count the number of branches below the player (the player has passed them), then have the branches count if their y value is greater than the y value of the player - ONLY ONCE.

NOTICE: I am not giving you the code, but the idea - of how to accomplish what you wish to do. It can be done in GML or Drag n' Drop. Again, your choice.
 
M

Motivating

Guest
Yeah I'm using 2 objects to spawn branches, I'll test this on the left side maybe with a collision detection box for each time a branch hits the box for the counter? I'll mess around with it, thank you
 
C

ConsolCWBY

Guest
o_O ... Mind() = Blown;

I meant a counter, an internal variable; literally, a variable used for counting. :D
If you still are having problems figuring it out, message me through my account here and we can discuss some basics of variable use in private.
 
M

Motivating

Guest
Yea I'm literally brand new to making games, trying to learn and gain experience so I'm making a dumb game. I just don't know how to define the collision action yet. I want to make it so when the branch collides with an object 3 times it speeds up the vert. Here is my sorry excuse for code, I just dont know what would replace collision_point for an actual object

Code:
col = collision_point(x, y, Left_Branch, false, true)
if col = 2 then Vertspeed = +1
 
C

ConsolCWBY

Guest
GML is rather dense I've found.
place_meeting(x, y, ob);
give the x & y coords and the object that the current one is colliding with - returns true or false:

if place_meeting(x_coord, y_coord, specific_object)

So, if I were to use the above to look for a collision between my player object (obj_plyr) and an enemy object (obj_enemy), I would place it in the step even of my player object like so:

if (place_meeting(x, y, obj_enemy))
{
/*
Do some code;
*/
}

In this way, I am using the obj_plyr 's x & y to check.
 

Chaser

Member
Maybe set a variable "global.branchspeed"

In the create event of your branch object set a code

If global.branchspeed = 1

Your branch speed = whatever.

Then, Outside room you could destroy the instance and set global.branchspeed +=1 and create another branch object

Then The new created branch object would go at the speed that the global.branchspeed is set at.
Example
If global.branchspeed = 10
{
Vspeed = 10
}
 
M

Motivating

Guest
to simplify things so I understand them at a more basic level how would I create a collision event when Left_Branch (the left branch) hits the line then vertical speed is increased by +1?
 

Nux

GameMaker Staff
GameMaker Dev.
there's a reason why checking a line collision will not work, this is because it will be in contact with the line for a lot of frames, and each frame it is in contact with the line will increment the speed, basically passing one branch would increase the speed exponentially
I believe what wagyu said is the easiest way to do this:

in your branch objects do this:
make a new event > other > outside room

and then put this in a code block:

this means that every time a branch goes offscreen, the counter will increase by 1.
to check for every 10 branches a very VERY simple way is to use the modulo expression which will return 0 for every multiple of [x] if x = 10, so: 0, 10, 20, 30, 40, 50.
so in your two objects you are using to create branches you can check this state and if global.gotsagofest is a multiple of 10, then set it to that value / 10, e.g:
if global.gotsagofest is 0 then the speed will be 0 / 10 which is 0;
if global.gotsagofest is 10 then the speed will be 10 / 10 which is 1;
if global.gotsagofest is 50 then the speed will be 50 / 10 which is 5;

like this:

Code:
if ( global.gotsagofest mod 10 == 0 ) // if it is a multiple of 10
{
     global.branchSpeed = global.gotsagofest / 10;
}

the speed will be in a seperate variable such as
global.branchSpeed, you would then use this speed value to control how fast your branches are spawned! QwQ
 
M

Motivating

Guest
OK so I think I'm getting on the right track but I'm still getting an error, I think the issue is now I'm not sure how to define gotsagofast now with it being the counter for every branch that goes off the screen. Here are images of the code and the error I'm getting.

Problem1.png problem2.png
 
M

Motivating

Guest
Changed create to .global to match up with the outside room event, will test. And defined branchSpeed.global to = vspeed. Here are pictures of the new code, not working as intended. Any suggestions?

Newcode1.png
 
M

Motivating

Guest
Here is an video example of my project to show what I'm trying to go for little better, the fall speed is just giving me issues. Sorry for the crappy quality

 

Nux

GameMaker Staff
GameMaker Dev.
because you're reseting the branch speed every time you create a new object.
you have an object creating the branches, so that's where you want to do all the calculations, not in the branches themselves.
in the create event of the object that creates the branches (not the branch object but the object that creates the branches) initialise global.branchSpeed and global.gotsagofest to the values you want (vspeed and 0)
create: (for the controler)
Code:
global.branchSpeed = vspeed;
global.gotsagofest = 0;
and in the step event you want to check if 10 branches have passed (albeit the mod way is pretty confusing so do it this new way)
step: (for the controler)
Code:
if ( global.gotsagofest >= 10 )
{
    global.gotsagofest = 0; // reset counter
    global.branchSpeed += 1; // change this for how fast you want it to increase by
}
instead of having all the code in your branch you should only check if it is outside of the room, and if it is then increase global.gotsagofest by 1 and destroy the instance
outside room: (for branch)
Code:
global.gotsagofest += 1;
instance_destroy();
also, this error:
OK so I think I'm getting on the right track but I'm still getting an error, I think the issue is now I'm not sure how to define gotsagofast now with it being the counter for every branch that goes off the screen. Here are images of the code and the error I'm getting.

View attachment 1618 View attachment 1619
...is because you had spelt a variable name wrong
 
Top