Legacy GM draw_text value not changing when something happens | 3D

C

Coder123

Guest
so i have some text that is being displayed on the screen which is this:
draw_text(96, 32, "Wood: " + string(log_count));


the text is displayed fine but when i pickup a wooden log the value dosent update.

Heres my step event:

//Picking up wood logs


var inst, ex1, ey1, ez;
inst = instance_nearest(x, y, woodlog);
if inst
{
ex1 = inst.x
ey2 = inst.y

if keyboard_check_pressed(ord('E'))
if point_distance_3d(x, y, z, ex, ey, z) < 50
{
log_count += 3;
instance_destroy(obj_WoodLog);

}
}
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I'm assuming the draw code is in the same object as the one that's doing the picking up?

Also, you should do the keyboard check BEFORE the instance check, as it is a lot cheaper to run... ;)
 
C

Coder123

Guest
yes the code is in the same object as the on thats doing the pick up
also thanks for that lol i didnt know
 

Alexx

Member
If there is more than one instance of obj_WoodLog, the following won't work as expected:
GML:
instance_destroy(obj_WoodLog);
You need get the id of the instance and then destroy that.
 
C

Coder123

Guest
and how would i get the id of the instance? dumb question i know
tho i forgot to tell you, there isnt more than one instance of obj_WoodLog
 

chamaeleon

Member
and how would i get the id of the instance? dumb question i know
tho i forgot to tell you, there isnt more than one instance of obj_WoodLog
Are woodlog and obj_WoodLog two different objects, or is woodlog an instance, or is woodlog really supposed to say obj_WoodLog in your first post? Your naming convention makes for confusion, I think.
 
C

Coder123

Guest
Let me explain, when you cut a tree in my game, one instance of obj_WoodLog is being created.
 

chamaeleon

Member
Ignoring the object naming for a moment, have you tried debugging your program to determine what the value of log_count is at various points in time?
 
C

Coder123

Guest
i dont understand anything since thats gamemaker studio 2 and im using the legacy one
 
C

Coder123

Guest
Well I have it as a tag in the title "LEGACY GM"
anyways I cant really seem to find anything using the debug, perhaps this is just a dumb error from my code or something
 

chamaeleon

Member
Dumb error or not (everyone has errors in one way or the other from time to time), you need to determine if you are incrementing the variable at all (use the Debugger to find out that the line executed), or if any other line executes that modify the same variable (resets to zero for example), or if you are modifying a different variable than the one being displayed (modify one instance, another instance draws or draws over, etc.)
 
M

ManiacCoder

Guest
try this:

draw_text(96, 32, "Wood: " + log_count);
-----------------------------------------------
var inst, ex1, ey1, ez;
inst = instance_nearest(x, y, woodlog);
if inst
{
ex1 = inst.x
ey2 = inst.y

if keyboard_check_pressed(ord('E')) and point_distance_3d(x, y, z, ex, ey, z) < 50
{
log_count += 3;
instance_destroy(obj_WoodLog);

}
}
 
C

Coder123

Guest
also nope


___________________________________________
############################################################################################
FATAL ERROR in
action number 2
of Draw Event
for object obj_player:

DoAdd :: Execution Error
at gml_Object_obj_player_DrawGUI_2 (line 1) - draw_text(96, 32, "Wood: " + log_count);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_player_DrawGUI_2 (line 1)
 
C

Coder123

Guest
i tried that and it didnt work :/ the value is still not updating on the screen.
 

chamaeleon

Member
i tried that and it didnt work :/ the value is still not updating on the screen.
Put show_debug_message() with meaningful content before and after changing the value (adding, subtracting, initializing to a zero value, etc.), inside and outside, before and after if statements or other conditions that may prevent the code from running.
 

Tony Brice

Member
I think Alexx is on the right track here. Unless i'm missing something then the line

instance_destroy(obj_WoodLog);

should actually be instance_destroy(inst);

You've loaded var inst with the object id of the nearest instance of obj_wood at the start of the code, and you're picking that up, so you need to remove that one, and that one only.

With your instance_destroy(obj_WoodLog) you are actually removing all instances of it that are present. If you only have one instance then it won't matter - but that's probably not the case.

So, to come back to your log_count not updating issue, I suspect that's because you have declared that variable in the create event of obj_WoodLog, and it won't be doing anything because you're deleting them all as soon as one is picked up. You could get round this with a global variable declared somewhere which isn't going to be removed as one solution.
 
C

Coder123

Guest
I will try, thanks!

Nope value is still not updating even after I used inst instead of obj_WoodLog.

And no I didn't declare that var in obj WoodLog and I did it in obj_player (which is prob a stupid idea)

Quick update: I fixed my problem, turns out I had a bunch of weird code in my wood log object and I just removed that and it worked.
 
Top