Page 4 of 6

Re: help with script teleport

Posted: May 3rd, 2011, 1:38 pm
by Ryan
no mate i've run teleport scripts before and i also adjusted them so setting new teleports but only by following instructions given by megazor. it was a .gsc file and i always create these like this: i open notepad++ and click on save as and then put ".gsc" as file extension... tell me if you know a better way to create these...

then i put it into the cb_custom.pk3 and with a few changes in the main .gsc file of the .pk3 launching the teleport script when loading the mod, i uploaded it to the ftp, restarted server and it worked...

Re: help with script teleport

Posted: May 3rd, 2011, 1:41 pm
by Rezil
Try this:

Make three seperate functions. The first function, fA(param) should return the square of the parameter <param>. The second one, fB(param) should return a boolean(true/false) on whether the parameter <param> is divisible by 3(use modulus - %). The third one, fC(param1, param2) returns a string is this format: "<param1>:-:<param2>".

This one sounds really fun now that I've made it up, give it a go. :D

Print all three using iprintln.
In case you missed it above.

Re: help with script teleport

Posted: May 3rd, 2011, 1:43 pm
by megazor
given a string, need to convert it to lowercase one.

example: rYaN -> ryan

the making of that script will give you the knowledge of some new things such as size

Re: help with script teleport

Posted: May 3rd, 2011, 1:46 pm
by Drofder2004
Rezil wrote:In case you missed it above. [...]
I think that may be a small step ahead, without explaining functions and parameters this will be very confusing.

Re: help with script teleport

Posted: May 3rd, 2011, 1:48 pm
by Rezil
But it's all in your tutorial, so there is no excuse. If he needs further explanation than the one given in your tut, he can ask.

In the meantime:

Code: Select all

main()
{
	integer = fA(25);
	trueBool = fB(39);
	falseBool = fB(5);
	stg = fC(3, "A"); //interestingly enough, in quakeC you don't need to define the type of a variable
	iprintln(integer+" "+trueBool+" "+falseBool+" "+stg);
}

fA(param)
{
	return (param*param)
}
fB(param)
{
	if(param%3==0) return true;
	else return false;
}
fC(param1, param2)
{
	return param1+":-:"+param2;
}
[/size]

Solution here, quote my post/zoom in if you want to spoil it for yourself. :)

Re: help with script teleport

Posted: May 3rd, 2011, 1:50 pm
by Drofder2004
Rezil wrote:But it's all in your tutorial
Its been a while, that could probably do with a revamp.

Re: help with script teleport

Posted: May 3rd, 2011, 1:51 pm
by IzNoGoD
megazor wrote:given a string, need to convert it to lowercase one.

example: rYaN -> ryan

the making of that script will give you the knowledge of some new things such as size

Code: Select all

randomFunction(string)
{
return tolower(string);
}
Why rewrite a built-in function? :P

Re: help with script teleport

Posted: May 3rd, 2011, 2:11 pm
by Ryan
IzNoGod no offense meant m8 but can you please stop spoiling my exercises i'm sure mega is competent enough to have known this function for years he just wanted to give me a task to do... he created a fucking minecraft mod for cod1 so i'm sure he knows that this command is an actual built-in function...

KS i've given it a try:

Code: Select all

for(i=0;i<21;i++)
{
        var = i * i;
        
        if(var % 2 = 0);
        {
                iprintln(i+"x"+i+" equals "+(i*i). This is EVEN);
        
        else
                iprintln(i+"x"+i+" equals "+(i*i). This is ODD);
        }
}

Re: help with script teleport

Posted: May 3rd, 2011, 2:21 pm
by Rezil
There we go, actual progress. I hope you understand what modulus does now. :)

You're missing a closing bracket at the end of your if statement and the semi-colon at the end of it shouldn't be there(syntax error). And your if statement is wrong, as you're not comparing, but assigning a value(one '=' instead of two). Also, it would've been more economical to store the odd/even in a seperate string variable and then use only one iprintln, like this:

Code: Select all

for(i=0;i<21;i++)
{
        result = i*i;
        str = "";
        if(result%2==0) str = "EVEN"; 
/*single line if statements reach only until the end of the next statement(str = "EVEN"; in our case) */
        else str = "ODD";
        
        iprintln(i+"x"+i" equals "+result+" which is "+str);
}

Re: help with script teleport

Posted: May 3rd, 2011, 2:29 pm
by megazor
we save bits.

two following parts of code behave the same
if (lol == true) return true;
else return false;
if (lol) return 1;
return 0;
-------

regarding a toLower function, yes, i knew it was a built-in function (not in cod1 though).

but why not develop brains? :) so now have a go writing that.

Re: help with script teleport

Posted: May 3rd, 2011, 2:34 pm
by Ryan
Rezil wrote:Make three functions. The first function, fA(param) should return the square of the parameter <param>. The second one, fB(param) should return a boolean(true/false) on whether the parameter <param> is divisible by 3(use modulus - %). The third one, fC(param1, param2) returns a string is this format: "<param1>:-:<param2>".

This one sounds really fun now that I've made it up, give it a go. :D

Print all three using iprintln.
after trying for a few mins i gave up cos this is impossible to do... think before you post whether this is of suitable difficulty...

give me a few mins i've just finished KS thing then i failed at rezils now ill try mega's and ive got other things to do as well ...

... ok after failing at megazor's cos i've got no idea whatsoever since i've never seen any tutorial or instruction how to do this i would like to request considering your posts before you make them since i cba reading through all your highly complicated pseudocodes i dont understand ending up in a task ive never been taught how to make so please show some understanding...

Re: The 'QuakeC lessons' thread[prev. help with script telep

Posted: May 3rd, 2011, 4:15 pm
by megazor
ok, size.

the size of a string variable is the amount of characters that make the string up.
for example, the size of the string "lol" is 3.
to get the string size, use

Code: Select all

rofl.size
in the above code, rofl is a string

another example

Code: Select all

str = "megazor is pro";
iprintln(str.size);
that will print 14. yes, it counts spaces.

now about certain characters:

say we have some string, how do we get the first character of it?
simply:

Code: Select all

str = "ryan";
iprintln(str[0]);
remember that the string index always starts from 0, not from 1. so, to get the second characher of the same string, "y", you will want to use

Code: Select all

iprintln(str[1])
well, the function toLower comes here:

Code: Select all

toLower()
{
	string = "rYaN";	//a string to convert, changeable
	big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";	//string that contains all latinic letters - uppercase
	correct = "abcdefghijklmnopqrstuvwxyz";		//the same as previous, but lowercase
	correctString = "";	//empty string that will be being filled with correct characters
	for (i = 0; i < string.size; i++)	//for each characher in 'string' (which size is 4, can you see that?), do:
	{
		s = string[i];	//'s' is a new variable which gets the value of 'string[i]'. if 'i' equals 0, string[i] being "r", and when 'i' equals 1, string[i] being "Y", etc
		for (a = 0; a < big.size; a++)	//now check through 'big' if this character ('s') is inside it. if so, then it's uppercase.
			if (s == big[a])	
			{
				s = correct[a];	//change 's' to lowercase. so, if 's' being "Y", it will become "y".	pay attention to the fact that the letters in 'big' and 'correct' are equal, the only difference is being lower/uppercase
				break;	//break 'big' loop, no need to check for that character any longer as it's been corrected.
			}
		correctString += s;	//add the character (which might have been converted to lowercase) to the string 
	}
	//all the characters have been checked out and converted if they were to.
	iprintln(correctString);
}

Re: The 'QuakeC lessons' thread[prev. help with script telep

Posted: May 3rd, 2011, 4:24 pm
by Ryan
after reading through the scripting for dummies thread twice only for your task (not to tell you the other 50 thousand times i've read through it) and reading a whole array topic on a cprogramming site this is the only thing i can come up with and i'm 100 % sure its wrong:

Code: Select all

int callofduty1 = [21]

for(i = 1; i <=20; i++)
	{
		iprintln(callofduty1.size); //forwards here
	}
for(i = 20; i >=1; i--)
	{
		iprintln(callofduty1.size); //backwards here
	}

Re: The 'QuakeC lessons' thread[prev. help with script telep

Posted: May 3rd, 2011, 4:35 pm
by Ryan
megazor wrote:...
and you were seriously expecting me to be able to do that with my shit noob knowledge? i started a few days ago and have done like 3 tasks successfully and you expect me to be able to do that?

Re: The 'QuakeC lessons' thread[prev. help with script telep

Posted: May 3rd, 2011, 5:03 pm
by Drofder2004
Ryan wrote:after reading through the scripting for dummies thread twice only for your task (not to tell you the other 50 thousand times i've read through it) and reading a whole array topic on a cprogramming site this is the only thing i can come up with and i'm 100 % sure its wrong:

Code: Select all

int callofduty1 = [21]

for(i = 1; i <=20; i++)
	{
		iprintln(callofduty1.size); //forwards here
	}
for(i = 20; i >=1; i--)
	{
		iprintln(callofduty1.size); //backwards here
	}
The idea is there but wrong execution. The for loops are fine however.

Firstly, with CoDScript you do not need to declare the size of an array or require the 'int'.
You can type simply "arrayName = [];"
That is your array created.

Firstly KS, said to store the numbers inside the array.
To store number in an array we use the following syntax:

arrayName[arrayname.size] = <value>;
to explain what is going on:

Firstly "arrayName" is simply the name we called our array. like a variable, call it what you want.
Secondly, we use the value of "size".
Arrays are an index. Indexes start at ZERO.
So, the current SIZE of the array is ZERO.

arrayName[arrayName.size]
is the same as
arrayName[0]

When we add a value to the array, the array size now becomes 1.
So arrayName[arrayName.size] now equals arrayName[1], etc.

So, we can create an array and populate it using a loop.

Code: Select all

/* Create your array outside the loop */
arrayName = [];
 
for(i=0;i<21;i++)
{
   arrayName[arrayName.size] = i;
}
You will now have your array of 20 values.

From here, you were asked to print them out.
Your loops were correct, but your prints were slightly wrong.

Instead of printing the size, you print the value.
iprintln(arrayName);

So, your final code will look like:

Code: Select all

/* Create an array */
callofduty1 = [];
 
/* Populate your array with values */
for(i=1;i<=20;i++)
{
   callofduty1[callofduty1.size] = i;
}
 
/* Print the values from 1 to 20 */
for(i = 1; i <=20; i++)
{
   iprintln(callofduty1[i]); //forwards here
}
 
/* Print the values from 20 to 1 */
for(i = 20; i >=1; i--)
{
   iprintln(callofduty1[i]); //backwards here
}
I urge you to understand the above final piece of code before you try and continue, and do not be confused with Pseudocode, it is just the method of reading code to make it udnerstandable.

When you read your code out loud and make understanding of it, your are essentially thinking Pseudocode.
Also, ignore Megazors exercise, the difficulty level of it was not even amateur let alone beginner...