N
NTiger7
Guest
IDE v. 2.3.0.529 and runtime v 2.3.0.401
So I'm trying make a shop for my game where the player presses the "w" key in the trigger area and then the shop opens up. It can display 3 items at a time and if there are more than 3 items then there is a scroller that will change the items that are displayed. The problem is that for my scroller, to calculate the percentage of the scroller (as in 0% at top and then 100% percent at the bottom), it needs to know the y coordinate of the scroller, and it can't do that when it isn't spawned in until the player interacts with it. I'm trying to make a code where if the scroller is at a certain percentage, then the items available for the player to purchase change. Here is the code for the scroller (the slider part of the scroller):
This is the slider code located in the step event:
This is the slider code in the left pressed event:
On left release, grab = false.
Here is part of the code in the CSShop object that deals with the percentage line, in the draw GUI event:
Is there a way I can make it so that the percentage will be set to zero until the player interacts with the slider? This is the only solution I can think of at this time. Thank you for any responses.
So I'm trying make a shop for my game where the player presses the "w" key in the trigger area and then the shop opens up. It can display 3 items at a time and if there are more than 3 items then there is a scroller that will change the items that are displayed. The problem is that for my scroller, to calculate the percentage of the scroller (as in 0% at top and then 100% percent at the bottom), it needs to know the y coordinate of the scroller, and it can't do that when it isn't spawned in until the player interacts with it. I'm trying to make a code where if the scroller is at a certain percentage, then the items available for the player to purchase change. Here is the code for the scroller (the slider part of the scroller):
This is the slider code located in the step event:
GML:
if (!mouse_check_button(mb_left)) grab = false;
if (!grab) exit;
else {
if ((mouse_y + yy < oBar.bottomLimit) && (mouse_y + yy > oBar.topLimit)) y = mouse_y + yy;
else if (mouse_y + yy > oBar.bottomLimit) y = oBar.bottomLimit;
else if (mouse_y + yy < oBar.topLimit) y = oBar.topLimit;
}
percentage = round(((oSlider.y - oBar.bottomLimit) / (oBar.topLimit - oBar.bottomLimit)) * 100);
GML:
grab = true;
yy = y - mouse_y;
Here is part of the code in the CSShop object that deals with the percentage line, in the draw GUI event:
GML:
if (CSshop_UI_bg_height <= CSshop_UI_height * ii) {
instance_create_layer(CSshop_UI_bg_width, CSshop_UI_bg_height, "Instances", oBar);
with (oSlider) {
if (percentage == (other.CSshop_UI_height / other.CSshop_UI_height * shop_items)) {
for (var i = 0; i < 3; i++) {
inv_grid = other.ds_CSshop;
yy = other.CSshop_UI_y + (i * other.CSshop_UI_height * other.scale);
iItem = inv_grid[# 0, i + 1];
sx = (iItem mod other.s_CSshop_items_columns) * other.cell_size;
sy = (iItem div other.s_CSshop_items_columns) * other.cell_size;
draw_sprite_part_ext(
other.s_CSshop_UI, 0, 0, 0, other.CSshop_UI_width, other.CSshop_UI_height, xx, yy,
other.scale, other.scale, c_white, 1
);
if (i = 1) {
draw_sprite_part_ext(
other.s_CSshop_items, 0, sx, sy, other.cell_size, other.cell_size, ((other.CSshop_UI_width * other.scale) + (78 * other.scale)),
((52 * other.scale) + (i * (other.CSshop_UI_height - 26) * other.scale)), other.scale, other.scale, c_white, 1
);
} else {
draw_sprite_part_ext(
other.s_CSshop_items, 0, sx, sy, other.cell_size, other.cell_size, ((other.CSshop_UI_width * other.scale) + (78 * other.scale)),
((54 * other.scale) + (i * other.CSshop_UI_height * other.scale)), other.scale, other.scale, c_white, 1
);
}
}
}
}
ii = 0;
}