Windows Need help with string not updating

Rexzqy

Member
Right now I am implementing a temperature system, and the thermometer item could show the temperature right now. However, it wont update and would just show the default value even though the value changes. Any help is greatly appreciated!

ds_item_info[# z ,i++] = "The temp now is "+string(temp)+"C" //showing the current temperature
temp = global.temperature; // in create event
global.temperature = 20;

and i set up a function where if u press key 1 it would increase global.temperature by 1, and through debug message it shows me that the global temperature is going up. Any thoughts on how to fix this?
 

Mk.2

Member
If you want "temp" to update from its default value, then yes. The create event only runs once when the instance is created.
 

Rexzqy

Member
If you want "temp" to update from its default value, then yes. The create event only runs once when the instance is created.
i tried that and now it just gives me an error message said variable not set before reading... Also global.hp is updating properly when its placed in the create even
 

Mk.2

Member
i tried that and now it just gives me an error message said variable not set before reading... Also global.hp is updating properly when its placed in the create even
Post the step event code you have. It sounds like you've removed it from the create event, then placed it in the step event after referencing it instead of before.

global.hp is updating I assume because you're adding/subtracting from global.hp, unlike "temp" where you're adding to global.temp. If you want temp's value to update to the same as global.temp, it needs to be done in the step event.
 

Rexzqy

Member
Post the step event code you have. It sounds like you've removed it from the create event, then placed it in the step event after referencing it instead of before.

global.hp is updating I assume because you're adding/subtracting from global.hp, unlike "temp" where you're adding to global.temp. If you want temp's value to update to the same as global.temp, it needs to be done in the step event.
ds_item_info[# z ,i++] = "The temp now is "+string(global.temperature)+"C" // this is in create, its a ds_list

if (iitem >=0)
{
description = iinfo_grid[# 0, iitem] +". "+ iinfo_grid[# 1, iitem];
obj_quickslot.draw_texts = true;
draw_text_ext_color(obj_inv.desc_x,obj_inv.desc_y,description,string_h,inv_w*scale,c_black, c_black,c_black,c_black,1);
}
///this is in draw_gui

So i want the text to update base on the current temperature. Thx for helping!!!
 

Rexzqy

Member
And for increasing the temperature, its in the step even of the player. its like this
if (keyboard_check(ord("1")))
{
global.temperature += 1;
show_debug_message (string(global.temperature));
}
 

Nidoking

Member
ds_item_info[# z ,i++] = "The temp now is "+string(global.temperature)+"C" // this is in create, its a ds_list
You can't store a reference to a variable. This will grab the value of global.temperature one time, then forget where that value came from and just store the value forever. Your problem now is that you're doing this before the temperature was ever set.

With the exception of a few builtin variables like position and speed that affect each other, any time you want something to change, you have to tell it to change every time you want it to change. This has to be in the step event. Given that it's clearly in a loop, you're going to have to handle that in a non-loopy way, like figuring out what the i value for that item is and using that directly. An enum or map would be good for that. An alternative would be to use some kind of token in the string, like storing "The temp now is %%TEMPERATURE%%C" and then having whatever draws that text to the screen parse for tokens and replace them with the corresponding values. That, also, needs to be done every step.
 
Top