Name Interger with a String

hi, i need to name a Inter with a string that the user inputs. Here's the code;

void loop()
{
run(1,1,5, "block");
}

void run(uint16_t x, uint16_t y, uint16_t num, char ref[]) // X, Y, number of blocks, block name
{
int ref = 0; // this is where i want the interger to be named after the string "ref"
}

the code is for a game library I'm writing, the integer needs to be named by the string because it needs to be unique,

thanks for the help

You have to make a table in which the "internal names" of the integers are coupled to the external names of the userinput. If no useriput available, the external name COULD be the internal name. You can hardcode the internal names.

Check - http://www.arduino.cc/en/Reference/Array

Begin with an array of int's and let the user input the index number. Not exactly what you want but easier and you will learn some basics about arrays that you need for the complex solution.

Succes,

Wow, thanks confusing, thanks alot though ill give it a go :slight_smile:

Ok, i gave i gave it a read, then read it again but i couldn't find anything that names an integer after a string,

what i want to do i set the Name and not the Value of the integer, using a string. When i said the user inputs it, i mean that it's input during programing.

I know i could do it in a much simpler way by simple typing the integer names manually but i want to automate it to make it easier in the long run.

jaggernought:
i mean that it's input during programing.

How is it going to be input during programming?

You cannot name a variable after compile time, you can have a table with names associated with the right variable.

Another option would be to define a class that holds an integer and its name. Then you can create code that assigns a name to the object. Then the object would have a name and an integer value.

Or do a lot of stringcompares and calculate an index for an array like below.

int array[10];

void run(uint16_t x, uint16_t y, uint16_t num, char *ref)  // X, Y, number of blocks, block name
{
  int idx = -1;
  if (strcmp(s, "name1") == 0) idx = 1;
  if (strcmp(s, "name2") == 0) idx = 2;
  if (strcmp(s, "name3") == 0) idx = 3;
  if (strcmp(s, "name4") == 0) idx = 4;

  if (idx > -1) array[idx] = 0;
 ...
}

Hopes this helps ...

Ah, thanks allot for the help.

Think i understand now, thanks allot