RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
how do I deal with a null?

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 82
We learn by living...
I have a simple script for determining if you are using weapon A or weapon B, and it displays some info, I know there's going to be a "nil" result for atk  but I don't know how to address that fact and say "draw text nothing"

My script is as follows.

Code: [Select]
      if wpn_num >= 17
  self.contents.draw_text(484, 256, 96, 32, $data_weapons[wpn_num].atk.to_s)
    self.contents.font.color = system_color
  self.contents.draw_text(524, 224, 96, 32, "Rng")
    self.contents.font.color = normal_color
  self.contents.draw_text(576, 224, 64, 32, $ABS.RANGE_WEAPONS[wpn_num][4].to_s)
     else
if $data_weapons[wpn_num].atk != nil       
       self.contents.draw_text(469, 256, 96, 32, "+ " + $data_weapons[wpn_num].atk.to_s)
     else
       self.contents.draw_text(469, 256, 96, 32, "")
      end
       end

i'm not sure I parsed my "if" statement correctly either, actually.

***
Rep:
Level 90
Skilled Scripter, Shitty Mapper, Decent Writer.
You might want to try something like "unless weapon is nil?" to keep the code in the "unless" branch from running unless there's a valid weapon equipped.

***
Rep:
Level 82
We learn by living...
It was my fault not realizing "no weapon" is actually registered as "0" and not nil. the thing that is nil is the base atk of the weapon 0. I think it's probably possible to even modify the stats of your "0" weapon, which could be turned into a series of martial arts - but you didn't hear that from me...

So here's my fixed code counting in "weapon 0".
Code: [Select]
if wpn_num >= 17
  self.contents.draw_text(484, 256, 96, 32, $data_weapons[wpn_num].atk.to_s)
    self.contents.font.color = system_color
  self.contents.draw_text(524, 224, 96, 32, "Rng")
    self.contents.font.color = normal_color
  self.contents.draw_text(576, 224, 64, 32, $ABS.RANGE_WEAPONS[wpn_num][4].to_s)
elsif wpn_num < 17 && wpn_num > 0 
  self.contents.draw_text(469, 256, 96, 32, "+ " + $data_weapons[wpn_num].atk.to_s)
else
  self.contents.draw_text(328, 256, 112, 32, "Unarmed: ")
  self.contents.draw_text(469, 256, 96, 32, "No Bonus")
end