Scripting QuickLaunch

Status
Not open for further replies.

rohan

In the zone
Well, this tutorial I've made will be updated by me regularly. Recently I got addicted to Scripting thanks to MAKI, the kool scripting language and Vb. Then I thought there were many things that could very well, confuse new scripters and hence I thought this tutorial would help. Please add content to it. I will too... For today, there's one:

DataTypes: Why so many?

Let's consider numbers: Integers, Floats, Doubles, Singles and Booleans.

Integers: Any integeral number between:-2 147 483 647 to +2 147 483 648 That means no decimals EVER

Float: It is a floating point number and can hold upto 4-7 decimal places {depends upon language} A float has a mantissa and an exponent.

Double: It is a floating point number wit h double precision.

Booleans: It can either be 1 or 0 i.e True or Flase or Yes or No.

String: It is a piece of text that cannot be computed mathematically.

All these as you see are nothing but numbers. A 0 or 1 can be a boolean, it can be an integer, it can be a float, a double or even a string. But then why does it have to be assigned as a boolean? why can't an integer be signed as a float? There are two reasons for it:-

1.Computing: Let's take the exaple of two integers: 2 and 472 for ex. Let them be assigned as Strings. Then let's add the two strings. You will get 2472. What it does is 'concatenation'. It joins, rather than adding. Do the same with 'hi!' and ' Hello'. You'll get 'hi! Hello'.

Whereas if you add, them as integers you'll get '474' as the result.

2.Space: Each data-type has a specific amount of data-space assigned to it. Even if it is of a smaller size, it will take that much space. Consider your fridge.

You have about 100ml of yellow butter, 200ml of white butter and 300ml of milk. You have various containers. You have 10 100ml containers, 20 200ml containers and 15 300ml containers. The total space in your fridge is the amount of computing space available to your program OR totla available memory. Now, what would leave you with containers, that can furhter accomodate the maximum space and also make the fridge less uncluttered. You'll put the 100ml ting in the 100ml container, 200ml thing in the 200ml container and so on. You wouldn't waste a 300 mL container on a 100ml thing.

Similarly, integers have 8 bytes capacity, floats have 16 bit capacity and so on. Hence to make things effecient, you need to assign the numbers properly. Like, an integer called '21' will be computed as an integer even if it was a 'float', but why waste the other '8 bit'. Even if that much space isn't reuired by your program, it will close the space for other programs too and in high buil-up softwares', such clutters mean 'doomsday'...

[thanX]

©Rohan Prabhu
 
OP
rohan

rohan

In the zone
sms_solver said:
why don't you provide some of the examples
Sure, i would love to...

Let's take the example for a script that calculates the volume and returns the value to be displayed somewher in terms of %.

First we name the variables:

In MAKI it's:-
Global Float volRating;
Global Int volRint;
Global :source: volume;
Global :display: text;

Here, :source: can be anything, but generally it's a slider.
:display: can be anywhere the data is to be sent.

Whereas in Java the 'Global' is replaced by 'var' and so on...

Now, let us get the 'value' of volume. In MAKI it's

Code:
volRating=Volume.getPosition();
{Here, volume is referred to as a 'slider' and it's position is being given..}

Now, we need to display it:

We get the values out of 255, but we want it out of 100. So what we do is multiply it by 100 and then divide by 255:

Code:
volRating=volRating*100/255;

Here, volRating is a 'float'. It is taking upto 9 bytes, whereas a percentage value can be fitted within just 2 bytes.. So,what we do is convert it to an 'integer'

Code:
System.integerToString(volRating);

But, here volRating still takes the same place as was taken by a float because volRating was defined as a float. Hence we use the integer we defined as 'volRint'.

Code:
volRint=volRating;

But, now it's taking both the space of a float and also the space of an integer!!! So, we'll remove the Float..

Code:
volRating.delete;

Now, just by doing this, we saved upto 7 bytes...

For displaying purposes, it needs to be converted into a string. Hence, what we'll do is convert it in realtime, whereas not modify the 'volRating' integer. This is necessary as a String takes upto 16KB. That;s a lot of it..

Code:
text.setText(System.integerToString(volRint));

That's it, so you see. Had we not taken the pains to convert, our program which has such a small purpose would have clogged upto '16KB + 9 bytes' whereas we did it to only 2 bytes. So what do you think would happen to bigger programs like the OSes you're running?

©Rohan Prabhu
 
Status
Not open for further replies.
Top Bottom