Global Variable vs variable

Non-platform specific questions.

Global Variable vs variable

Postby raminkhan » Sat Dec 17, 2011 4:12 am

okay my question is what is the difference between char, int, string variables because I just went into the script editor and just simply created a variable and it was int type but now I am trying to make a if statement and make a conditional statement but I am having trouble.

this is my script:

if(Coll==1)
{
do this;
}
else if(Coll!==1)
{
do something else;
}

but it gives me errors like can not convert from char to int or unknown binhost, incomplete type and so on. so what am I doing wrong?

also how can I make my own functions and variables with global code?
raminkhan
 
Posts: 63
Joined: Mon Sep 12, 2011 3:35 pm
Score: 0 Give a positive score

Re: Global Variable vs variable

Postby skydereign » Sat Dec 17, 2011 4:43 am

A char is a character, and int is an integer, a float is a floating point number, a double is a large floating point number, and a string is an array of chars. If you are comparing with using those statements you should be dealing with ints. Make an int variable, and it should work. Perhaps you messed up when creating it. One thing to note, your else if statement is redundant, you might as well just say else, as if it does match the equals one, then of course it is not equal to one.
Code: Select all
int Coll;
if(Col===1)
{
    // do this
}
else
{
    // do this
}

The above code should work, if you want to make your Coll variable global, put the first line into global code.

Now to write functions, just put them in global space.
Global Code
Code: Select all
int Coll;

void // return type
function (int parameter) // function name (parameter list)
{
    // do stuff
}


int // returns an int
is_even (int num) // named is_even and passes a number to it
{
    return(num%2==0); // returns the result, 1 if it the number is even, 0 if not
}


To declare variables in global code, just write them out, like in the above (first line declares an int Coll).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Global Variable vs variable

Postby raminkhan » Sat Dec 17, 2011 5:09 am

thanks sky but 2 q what do you mean by parameter should I just put a number or type parameter and also when you said is_even whats that? thanks bro.
raminkhan
 
Posts: 63
Joined: Mon Sep 12, 2011 3:35 pm
Score: 0 Give a positive score

Re: Global Variable vs variable

Postby skydereign » Sat Dec 17, 2011 5:38 am

is_even was just an example function. It follows the proper format, and was used to show how return works (the return type must be returned by the function, and in is_even's case returned an int). A parameter is a variable that you pass to the function. So, if you want a function to have some information you pass it a parameter. You've dealt with gE's built in functions, such as ChangeAnimation. You pass it two strings and one int. If you want to declare several parameters, you just do it as follows.
Code: Select all
int
some_function (int a, int b, int c)
{
    // do stuff with a b and c
    return a;
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest