• The Eevee Expo Game Jam is on! 📝 Head on over to the game jam forum and read through the rules if you want to participate.
    From June 30th to August 10th, 2025, participants have a little over a month to create a game!
  • Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.

Key not found in a hash

Sulucnal

Novice
Member
Joined
Sep 7, 2020
Posts
14
I'm pretty unfamiliar with Essentials and Ruby and am trying to implement a mechanic to make apricorn trees grow according to a timer.
To do so, I have a time_event_hash variable meant to contain every time-sensitive event where each entry would be a combination where the key is an event's unique id and the value is the time at which said apricorn's growth would be complete (in unix time).

I then have a loop in my event that compares the current unix time to the time at which the growth on my apricorn is meant to be reached by using this function:
Code:
Expand Collapse Copy
pbGetTimeNow.to_i >= time_event_hash[get_time_event_id]
However, it makes my game crash, telling me that it can't compare an integer with a Nil value, implying that either the time_event_hash[get_time_event_id] == Nil, or that the key associated to my apricorn tree doesn't even exist.

To make sure of it, I decided to check if my hash contains the appropriate key and print the content of said hash in the command prompt if it doesn't.
Here is my code:
Ruby:
Expand Collapse Copy
if time_event_hash.key?(get_time_event_id)
    echoln "%s not found in hash!" % get_time_event_id
    echoln "%s" % time_event_hash
end
And here is what it printed out:
apricorn_tree_6_10 not found in hash!
{"apricorn_tree_6_10"=>1751460881}
Does anyone know why I can't find my key in my hash while it clearly has it and what the solution to that problem could be?

Thanks in advance.
 
I'm pretty unfamiliar with Essentials and Ruby and am trying to implement a mechanic to make apricorn trees grow according to a timer.
To do so, I have a time_event_hash variable meant to contain every time-sensitive event where each entry would be a combination where the key is an event's unique id and the value is the time at which said apricorn's growth would be complete (in unix time).

I then have a loop in my event that compares the current unix time to the time at which the growth on my apricorn is meant to be reached by using this function:
Code:
Expand Collapse Copy
pbGetTimeNow.to_i >= time_event_hash[get_time_event_id]
However, it makes my game crash, telling me that it can't compare an integer with a Nil value, implying that either the time_event_hash[get_time_event_id] == Nil, or that the key associated to my apricorn tree doesn't even exist.

To make sure of it, I decided to check if my hash contains the appropriate key and print the content of said hash in the command prompt if it doesn't.
Here is my code:
Ruby:
Expand Collapse Copy
if time_event_hash.key?(get_time_event_id)
    echoln "%s not found in hash!" % get_time_event_id
    echoln "%s" % time_event_hash
end
And here is what it printed out:

Does anyone know why I can't find my key in my hash while it clearly has it and what the solution to that problem could be?

Thanks in advance.
There is already a built in way to save variables specific to events using setVariable and getVariable, so no need to recreate the wheel.

In a script call, do setVariable(val) where val is the time object you want to compare against.

Then, your comparison should be pbGetTimeNow.to_i >= getVariable
 
Back
Top