none
How to turn text into a variable RRS feed

  • Question

  • Hey everyone! I've programmed with Small Basic for 3 years now and I've come across a road block. I'm working on a card game, called Elementice, and i will include the Import ID (BJZ474). My problem is that i listed a bunch of variables in the beginning such as "od" For the card, "The omen of death", and then the value of damage it causes, for example,

    od=25

    So if you get this card, the other player (computer AI for now) loses 25 health. I hope that makes sense. But my problem is that when a player chooses to play a card, my program will get the subtext from the card, so "The Omen Of Death", I have a variable, getcardname1 (which is = to "Omen") and getcardname2 (which is = to "Death"). I then get the subtext using Text.Getsubtext() and i get the first letter of each (getcardname1 and getcardname2) so i come out with "OD". I then change it to lowercase and i now have my variable "final" which is now equal to "od"

    final="od"

    So now here is my problem. I want the enemyhealth variable to subtract the VALUE of "final", if that makes sense. It's obvious that "enemyhealth=enemyhealth-final" doesn't work:( I want it to see that the value of "final" is "od" and then get the 25 from my ORIGINAL variable od and subtract that from enemyhealth. I really hope this makes sense! Any help would BE SOO APPRECIATED, because I am on fire with this project haha :) Thanks for reading!!

    Friday, August 1, 2014 3:42 PM

Answers

  • Looks like you are off to a great start! Unfortunately, Small Basic doesn't support reflection, or accessing variables by a string of their name. 

    However, there is an elegant solution in your case--- arrays!

    You could define an array called "cards" and set values like this:

    cards["od"] = 25

    Then just subtract cards[final] from your score!


    Please mark any answers and "vote as helpful" any posts that help you!


    Friday, August 1, 2014 4:29 PM
    Answerer

All replies

  • Looks like you are off to a great start! Unfortunately, Small Basic doesn't support reflection, or accessing variables by a string of their name. 

    However, there is an elegant solution in your case--- arrays!

    You could define an array called "cards" and set values like this:

    cards["od"] = 25

    Then just subtract cards[final] from your score!


    Please mark any answers and "vote as helpful" any posts that help you!


    Friday, August 1, 2014 4:29 PM
    Answerer
  • Oh my! I never even thought of that! Thank you soooo much gungan!!! :)
    Friday, August 1, 2014 4:46 PM