
-----------------------------------
qmanjr5
Tue Dec 01, 2009 8:59 pm

Is it possible for a variable to be two or more types?
-----------------------------------
Such as

var example1 : int : string


or whatever.

-----------------------------------
Tony
Tue Dec 01, 2009 9:04 pm

RE:Is it possible for a variable to be two or more types?
-----------------------------------
just to try to understand what it is you are actually looking for...

if I was to have such a variable, and it held a value of "qmanjr5", but I used it as an int, what int value would you expect to have?

-----------------------------------
qmanjr5
Tue Dec 01, 2009 9:06 pm

RE:Is it possible for a variable to be two or more types?
-----------------------------------
Erm, no idea? :D

I have no idea what you mean.
An int is a number, not a string.
The reason I ask this is for my quiz I'm making. If I enter "lsmfpowe" for a question who's variable is an int, it screws up and won't continue. I realized this is because an int can't have letters (as far as I know?) so, I was wondering if I could make the variable be an integer and a string.

Or would I just put it as a string, since you can input numbers in a string?

-----------------------------------
Tony
Tue Dec 01, 2009 9:14 pm

Re: RE:Is it possible for a variable to be two or more types?
-----------------------------------
Erm, no idea? :D
That's exactly why I ask ;) It's now clear that what you ask to have, is not what you actually want.

Or would I just put it as a string, since you can input numbers in a string?Indeed.

You might also be interested in [tdoc]strintok[/tdoc] and [tdoc]strint[/tdoc] functions.

-----------------------------------
SNIPERDUDE
Tue Dec 01, 2009 9:22 pm

RE:Is it possible for a variable to be two or more types?
-----------------------------------
Use strings for your answers.  When you come across questions that require integers, Turing has built-n features such as strint (which converts a string to an integer), and strintok (which checks to see if a string can be converted to an integer, returning a boolean).  Just look them up in the Turing documentation.

EDIT: Tony and your fast posting

-----------------------------------
Kharybdis
Tue Dec 01, 2009 9:31 pm

RE:Is it possible for a variable to be two or more types?
-----------------------------------
A variable can't be an int and a string at the same time... that's just not possible.

I mean you can have the number 5 as a string.. but it would be declared as a string, not as an int.

You can interchange them if that's what you are seeking using the strintok, strreal, strint, and other functions.

EDIT: Wow, i'm such a slowpoke...

-----------------------------------
Tony
Tue Dec 01, 2009 9:38 pm

Re: RE:Is it possible for a variable to be two or more types?
-----------------------------------
A variable can't be an int and a string at the same time... that's just not possible
It is!

It's called a [url=http://en.wikipedia.org/wiki/Union_%28computer_science%29]Union. A variable is just a memory location that is holding some bits. Those bits could be interpreted as an integer, or as a string, or whatever else. In Turing, you can perform something similar via [tdoc]cheat[/tdoc]

-----------------------------------
SNIPERDUDE
Wed Dec 02, 2009 11:54 am

RE:Is it possible for a variable to be two or more types?
-----------------------------------
Well, that explains my query of was cheat is.  Thanks Tony!
