Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

What is wrong with dynamic constant assignment?

ComputingSquid
ComputingSquid

I wondering why this does not work

magicItem = ["Wand" , "Orb" , "Staff" , "Rod" , "Token"].sample weapon = ["Mace" , "Sword" , "Spear" , "Bow" , "Dagger"].sample boosts = ["Dodge boost" , "Attack Boost" , "Health boost" , "Defense boost" , "Spell Boost"].sample abilities = ["Instant kill" , "Extreme heal" , "Max damage" , "Spell damage Max"].sample def goShopping MagicItem1 = magicItem MagicItem2 = magicItem Weapon1 = weapon Weapon2 = weapon puts "Magic item number 1: #{MagicItem1}" puts "" if roll_dice(1,2) == 2 puts "Magic item number 2: #{MagicItem2}" else puts "" end puts "Weapon number 1: #{Weapon1}" puts "" if roll_dice(1,2) == 2 puts "Weapon number 2: #{Weapon2}" else puts "" end end

(Not fully finished, but you get the idea)
And outputs this error:

Traceback (most recent call last): 1: from main.rb:8:in `<main>' main.rb:8:in `require_relative': /home/runner/Replit-adventure-game/shop.rb:9: dynamic constant assignment (SyntaxError) MagicItem1 = magicItem ^ /home/runner/Replit-adventure-game/shop.rb:10: dynamic constant assignment MagicItem2 = magicItem ^ /home/runner/Replit-adventure-game/shop.rb:11: dynamic constant assignment Weapon1 = weapon ^ /home/runner/Replit-adventure-game/shop.rb:12: dynamic constant assignment Weapon2 = weapon ^ exit status 1

#####Why I did this was:

  • Because I wanted it so I could add something to a players inventory without it changing
  • I wanted variety, so I didn't have to have the exact same thing all the time

So yeah, you get the idea(i keep saying that, but why?) I dont't get why it outputs that error, maybe because a constant can't get changed, i'm not sure if ruby's like PHP's variable = var1 so if i change variable, var11 changes too

2 years ago

Voters

Comments

TopNew
2
DynamicSquid
DynamicSquid

I don't do ruby, but I found this

2 years ago
1
PattanAhmed
PattanAhmed

@ComputingSquid
Hi Squid,
Ruby is awesome, I know.

ruby

But you have some hard times getting your problems to get solved. :(
Check these websites that I found online. I think it may help you
1st website, 2nd website...

Please check those websites as it will be useful to you.

Hope this helps
Please mark my answer if this helps.

2 years ago
Load more