I'm trying to find a way to write in GUI for user that there is nothing in the button they just clicked
I've tried a method like `
if @album[@user_choice_album].tracks[10].name == nil
return
` But it interrupt the program and gave an message instead, while i was expecting it to interrupt the procedure and go to the next one.
test.rb:192:in `draw_now_playing': undefined method `name' for nil:NilClass (NoMethodError)
if (!(@album[@user_choice_album].tracks[10].name))\
It looks like you have
tracks
stored in an array (without knowing any details about your data structure and model). And when the user requests a track that doesn't exist, it returnsnil
.That means there is no point in asking if the
name
of that track isnil
when the wholetrack
isnil
.I guess this should work for you:
Or simplified: