andymeneely / squib

A Ruby DSL for prototyping card games.
http://squib.rocks
MIT License
923 stars 67 forks source link

Checking a condition (using if or case) #355

Closed LouisDeconinck closed 2 years ago

LouisDeconinck commented 2 years ago

The following code always returns 'No sun' even if the SunUp variable contains 1 or 2. I noticed that this is because data['SunUp'] is always an array. How can I change certain elements on the cards if a certain condition is met? Using ranges (https://squib.readthedocs.io/en/v0.18.0/arrays.html) seems a lot less flexible.

 case data['SunUp']
  when "1"
    png file: 'images/Sun-256.png', x: 300, width: 100, height: :scale
  when "2"
    png file: 'images/Sun-256.png', x: 300, width: 100, height: :scale
    png file: 'images/Sun-256.png', x: 420, width: 100, height: :scale
  else
    text str: 'No sun', x: 300
  end

  text str: data['SunUp']

In the example (https://squib.readthedocs.io/en/v0.18.0/arrays.html#examples), this code is used to identify the Thief and Grifter: text range: 0..1, str: 'Thief and Grifter only!!', x: 25, y:200 Wouldn't it be a lot more logical to check if the name of the card matches Thief or Grifter? That way, if the cards change position in your data, the code still works.

Is there any possibility of using case or if when using Squib? If not this would seem like a very useful function.

LouisDeconinck commented 2 years ago

The reason I want to use this, is that I want a card to either have 0, 1 or 2 Sun or 0, 1 or 2 Snow, but never both at the same time. Is there any other way how I could achieve this?

andymeneely commented 2 years ago

Let's finish this over on Discussion, it's not a feature request :)