• 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!

(solved )Set score for room

sweep

Member
Hi everyone

I am new to the forum and new Gamemaker.

I would like to set a score for an individual room to progress to the next. Eg: Reach 50 points , next room reach 100 points etc...

so far I have this in the player obj which i can't change.

if ( global.points >= 50)
{
room = room1;
}

Hope that makes sense. I have searched everywhere for the answer.
 
D

DarthTenebris

Guest
First, room is a read only variable. To actually change rooms, you need room_goto(). Second, to set the target score, an alternative to FrostyCat's solution would be to simply count how many rooms you've passed and multiply it with your target score interval to get the next room's target score.
Code:
Create:
score = 0;
target = 50;
interval = 50;
roomCount = 1;

Step:
if (score >= target * roomCount) {
     roomCount++;
     room_goto_next();
}
 

sweep

Member
Thank you for your help. one more question. Where would I place this code ? for each room I need to change the points target but then that affects the previous rooms.
Edit: placed in separate obj (obj_score

I would still like to set a unique score to each room. level one reach 50 points, level 2 reach 250 points. I've seen it done in drag and drop.
 
Last edited:

NightFrost

Member
What do you mean when you say it affects previous rooms? A list of score targets for each room is straightforward to do, but if player can return to previous rooms and the target score has to evolve, what your intent is affects the method of determining target score.
 

sweep

Member
I've placed obj_count into the room with this code. As soon as the score reaches 50 it moves to the next room. This works fine for room1 where the target is 50. If i change the target in one room it changes it for the whole game. what i am looking to do is this: level one reach 50 points to continue. level 2 reach 150 to continue etc...

STEP
if (global.points >= target * roomcount)
{
roomcount ++;
interval = 50
room_goto_next()

}
CREATE

global.points = 0
target = 50;
interval = 50;
roomcount = 1;
 

FrostyCat

Redemption Seeker
Since room IDs are numbers, they can be used to index an array of score targets.

Run this at the beginning of the game to seed the array:
Code:
global.target_score[rm_level1] = 100;
global.target_score[rm_level2] = 250;
global.target_score[rm_level3] = 500;
...
Then change your score check to this:
Code:
if (global.points >= global.target_score[room])
An alternative approach is with a map using room names.
Code:
global.target_score = ds_map_create();
global.target_score[? "rm_level1"] = 100;
global.target_score[? "rm_level2"] = 250;
global.target_score[? "rm_level3"] = 500;
...
Then the corresponding score check would be this:
Code:
if (global.points >= global.target_score[? room_get_name(room)])
Like NightFrost said, this is very basic, straight-forward material on variable handling and data organization.
 

Yal

šŸ§ *penguin noises*
GMC Elder
I second Frosty's approach. I recommend the ds_map approach, since room IDs aren't guaranteed to be contiguous (not every room is a level) and maps work the best for sparse data sets.

Though, I would add another layer of safety. Instead of
Code:
if (global.points >= global.target_score[? room_get_name(room)])
I would use
Code:
if (global.points >= room_get_target_score(room))
where room_get_target_score is a script with the following contents:
Code:
var sc = global.target_score[? room_get_name(room)];
if(is_undefined(sc)){
show_debug_message("WARNING: No target score defined for room " + room_get_name(argument0) + ", using default value.")
return 50;
}
else{
return sc;
}
This way you will get a default value of 50 for rooms you forgot to assign a target score to (and a debug message in the compile log).
 

sweep

Member
Thanks so much for your help everyone. The points and scoring are working perfectly !! I've only been using GameMaker for about a week so all this is new.
 
Top