By Dan's The Man
NOTE: I tried to make this as noob-proof as possible (by my standards ). So, if you like it or had learned something from it, could you also please give me some more reputation. This'll keep me writing more tutorials (since i won't think they're a waste of time to write). Thanks
Now that there's no tutorials on Variant's or TVariantArray's, i thought i'd post one so others can know what they are and how they work To continue, you need basic knowledge of SCAR and you need to know how arrays work, other than that, you're set to go
- What are Variants?
- How to use Variants.
- Understanding TVariantArrays.
- Putting it all together!
1 - What are Variants?
Variants is a variable type. As you'd probably know, types are variable declarations. So, to declare a Variant, we'd need something like:That would be a correct way how to declare a Variant, morally, any variable. Variants supports ANY type. So, it's like, all the types merged together. The string could be an integer, the string could be a boolean, an integer could be an extended value or string, etc. Ok, maybe what i had said before, about it being all types merged together, i was wrong, however, very similar. It's all type conversion methods joined together. That is like StrToInt, IntToStr, FloatToStr, Round.
2 - How to use Variants.
To simply put, they are used like any other variable type. You can do something similar to this code below:
You can see that Somethings' value is put in a string, but, when we put it in an if..then statement, we make it an integer. See, it manages to automatically convert itself.
Writeln('It''s 116!') else
Writeln(':o It isn''t 116!');
Again, with this example (above), we can see that when the script starts, it'll make Somethings' value 11 plus a random value of 499 and is an integer. But, in the repeat sequence, in Writeln, it is made, as a string. No IntToStr, no nothing. It's already made.
Writeln('Something is currently: '+Something);
3 - Understanding TVariantArrays:
Simple. TVariantArrays are arrays of Variants It has exactly the same structure as a Variant, however, the information is stored in an array. Even though you were probably expecting more from this section, but, that's all there is to it
Some procedures, such as ThreadSafeCall use TVariantArrays to store information, for some purpose (i can't find out ).
4 - Putting it all together:
function ConvArray(TVA: TVariantArray; Delim: String): Variant;
for i:=0 to High(TVA) do
procedure SendLines(TV: Variant);
CS, space: String;
for i:=1 to Length(TV) do
if(TV[i]=' ') then
CS:=Copy(TV, 1, Pos(space, TV));
function RandArray: TVariantArray;
for i:=0 to 99 do
case (Random(2)) of
TVar:=ConvArray(TVA, ' ');
Something similar to that (above) should work.
5 - An error you might encounter:
Is... [Runtime Error] : Exception: Could not convert variant of type (*) into type (*) in line * in script.
* - Will vary, depending on your script.
To error is pretty much self-explanatory It could not convert the variant of type * to another type of *. Such as a string to double. There's no way to over-come this, except to change the string in the Variant.
Add to my reputation if you like this tutorial
Thanks for reading and i hope you're one step further into SCAR Scripting than before!