[HELP] Error with my code

P

ProductivInc

Guest
draw_self();
if(mouse_check_button_pressed(mb_left)) (x,y,sprite_width,sprite_height))
draw_circle(x,y,TowerClickedAt,true);

What am I doing wrong? please correct the code for me. Error says 'nested function calls not allowed'
 
Really? You can't see what your problem is?
This is the problem:
Code:
(x,y,sprite_width,sprite_height))
You're not calling any sort of function there, so get rid of that bit of code.
Then tell us what you are trying to do as without that we won't be able to tell you what function you should be using instead of that made up code.
 
P

ProductivInc

Guest
Really? You can't see what your problem is?
This is the problem:
Code:
(x,y,sprite_width,sprite_height))
You're not calling any sort of function there, so get rid of that bit of code.
Then tell us what you are trying to do as without that we won't be able to tell you what function you should be using instead of that made up code.
Im trying to make a Tower upgrade system. And I will use if you click at the tower it will form a circle around so you can see that it is selected then a button will appear and from there you can click at it to upgrade.
 

Simon Gust

Member
You will need to create a Little more code.
A variable needs to keep track of which Tower is selected. Preferebly a global variable that is created in an object that controls your game if you have one.
This global variable holds the instance id of the selected Tower.
create of controller object
Code:
global.selected_tower = noone;
step of controller object
Code:
if (mouse_check_button_pressed(mb_left))
{
    var inst = instance_position(mouse_x, mouse_y, obj_tower);
    if (inst != noone) 
    {
        global.selected_tower = inst;
    }
}
else
if (mouse_check_button_pressed(mb_right)) 
{
    global.selected_tower = noone;
}
This code sets global.selected_tower to the id of the tower clicked on.
If you right-click, the tower will be deselected.
Now you need to draw that circle for which tower is selected
draw of controller object
Code:
with (global.selected_tower)
{
    draw_circle(x, y, 10, true);
}
That said, the draw event of every tower only has this
Code:
draw_self();
 
P

ProductivInc

Guest
You will need to create a Little more code.
A variable needs to keep track of which Tower is selected. Preferebly a global variable that is created in an object that controls your game if you have one.
This global variable holds the instance id of the selected Tower.
create of controller object
Code:
global.selected_tower = noone;
step of controller object
Code:
if (mouse_check_button_pressed(mb_left))
{
    var inst = instance_position(mouse_x, mouse_y, obj_tower);
    if (inst != noone)
    {
        global.selected_tower = inst;
    }
}
else
if (mouse_check_button_pressed(mb_right))
{
    global.selected_tower = noone;
}
This code sets global.selected_tower to the id of the tower clicked on.
If you right-click, the tower will be deselected.
Now you need to draw that circle for which tower is selected
draw of controller object
Code:
with (global.selected_tower)
{
    draw_circle(x, y, 10, true);
}
That said, the draw event of every tower only has this
Code:
draw_self();
Thank you so much for this! Do you know how I can change the color of the circle and change the opacity of it? If so please explain to me as detailed as possible. Also, Can I make so that when I click anywhere in the screen it deselects the tower? And one more thing, what does the last draw_self() do? Where do I need to put it?
 

FrostyCat

Redemption Seeker
Thank you so much for this! Do you know how I can change the color of the circle and change the opacity of it? If so please explain to me as detailed as possible. Also, Can I make so that when I click anywhere in the screen it deselects the tower? And one more thing, what does the last draw_self() do? Where do I need to put it?
Is this for real? You've been using GM since February and you don't even know what draw_set_colour() and draw_set_alpha() do?
Code:
draw_set_colour(c_red);
draw_set_alpha(0.5);
draw_circle(x, y, 10, true);
draw_set_alpha(1);
And if you aren't just another copy-and-paste skiddie like most of the "students" joining over the past few weeks, you'd also know what to do with Simon Gust's selection code to deselect upon not hitting anything:
Code:
if (mouse_check_button_pressed(mb_left))
{
   global.selected_tower = instance_position(mouse_x, mouse_y, obj_tower);
}
else
if (mouse_check_button_pressed(mb_right))
{
   global.selected_tower = noone;
}
instance_position() will return noone when there is no collision with the cursor, which when assigned to global.selected_tower is the selection-less state. The behaviour when there is a collision is the same as the original.

If you don't know what a function does, look it up in the Manual's Index tab instead of RTFM-baiting responders on the GMC. Here's the entry for draw_self().

You should put down your project and learn basic skills from a beginner-grade tutorial like the first 2 on this page. Every single topic you've posted thus far shows a complete lack of basics, most of which I could reasonably demand even of a week-old newbie. Handing every little hitch to an online forum is no way to program, get a clue and show some independence.
 
P

ProductivInc

Guest
Is this for real? You've been using GM since February and you don't even know what draw_set_colour() and draw_set_alpha() do?
Code:
draw_set_colour(c_red);
draw_set_alpha(0.5);
draw_circle(x, y, 10, true);
draw_set_alpha(1);
And if you aren't just another copy-and-paste skiddie like most of the "students" joining over the past few weeks, you'd also know what to do with Simon Gust's selection code to deselect upon not hitting anything:
Code:
if (mouse_check_button_pressed(mb_left))
{
   global.selected_tower = instance_position(mouse_x, mouse_y, obj_tower);
}
else
if (mouse_check_button_pressed(mb_right))
{
   global.selected_tower = noone;
}
instance_position() will return noone when there is no collision with the cursor, which when assigned to global.selected_tower is the selection-less state. The behaviour when there is a collision is the same as the original.

If you don't know what a function does, look it up in the Manual's Index tab instead of RTFM-baiting responders on the GMC. Here's the entry for draw_self().

You should put down your project and learn basic skills from a beginner-grade tutorial like the first 2 on this page. Every single topic you've posted thus far shows a complete lack of basics, most of which I could reasonably demand even of a week-old newbie. Handing every little hitch to an online forum is no way to program, get a clue and show some independence.
I am sorry, I'm really aware how bad I am. However, I've not been using GML since February. I don't use it at all often, just for school game projects. And the problem is that I wanna learn so bad but I'm literally having it hard to memorize code in my head, I understand what the some codes do when I read them, but to remember them and code them a week after is very hard. You have any tips for me?
 
Top