Page 5 of 6

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

Posted: May 3rd, 2011, 5:12 pm
by Rezil
Just a little addendum, if you plan on coding in a more flexible language, such as Java:

using arrayName.size is not advisable anywhere else other than in CoDScript because in other languages arrays are created with a fixed size. The 'proper' way to populate an array would therefore be:

Code: Select all

for(i=0;i<21;i++)
	array[i] = i;
Again, in CoDScript you can use the size of the array because it's dynamic, in Java/C you would get an 'index out of bounds' type of error.

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

Posted: May 3rd, 2011, 5:49 pm
by Ryan
i dont understand that array stuff at all... why do you put example = []; and why do you write example[example.size] = i

i dont get that "i" in every script why is it always "i" and not "a" or "codjumperkickzassbitchlol"

and why print "example" and not "example.size" whats the difference...

there are so many things i dont get i cannot explain cos its like so weird... all these names string variable loop i only type these into my dictionary and it gives me the words but to understand them is so difficult i cant explain it man...

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

Posted: May 3rd, 2011, 8:09 pm
by Moustache
Ryan wrote:i dont understand that array stuff at all... why do you put example = []; and why do you write example[example.size] = i

i dont get that "i" in every script why is it always "i" and not "a" or "codjumperkickzassbitchlol"

and why print "example" and not "example.size" whats the difference...

there are so many things i dont get i cannot explain cos its like so weird... all these names string variable loop i only type these into my dictionary and it gives me the words but to understand them is so difficult i cant explain it man...


You first create the array with: example = [];
Now the server knows example is an array, a group of things.

You want to add something to the array, lets say you want to add thing_to_add. First you create the thing_to_add.
thing_to_add = 10;
or
thing_to_add = "text to show";

Then you are going to add stuff to the array.
example[example.size] = thing_to_add;

Now example[0] contains the same as thing_to_add.

If you want to add something else.
second_thing = "more text";
example[example.size] = second_thing;

example[1] now contains the same as second_thing.

example.size is now 2. Because there are 2 things in the array example.

You can now for example do this:

Code: Select all

for( x = 0; x < example.size; x++) // here you can see you can use anything you want, instead of x or i or DeadOsamaBinLaden, it really doesn't matter.
{
   IPrintLnBold( example[x] );
}
In game you will see 2 lines with text:
text to show
more text
I think the stuff standing above is correct. If not come to my house and beat the living shit out of me. Or just correct me here.

Good luck with it :)

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

Posted: May 3rd, 2011, 8:30 pm
by Ryan
ok thanks mate its clearer now but to fully understand it i guess ill have to use it in tasks then eh?

if you guys decide to give me several more examples i will be very glad but please not too bloody difficult ones really... i dont do not read the tutorials but just say omg i cant do this shit, i do read them carefully, sometimes 3 times but its just hard for me to grasp these things... but the willingness is what keeps me going and i think i can do it so please give me more things but i'm sorry if i wont be able to do it :)

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

Posted: May 3rd, 2011, 10:09 pm
by Drofder2004
I always use the letter i in a counting loop, because that is how I learned it.

If you learn to use 'x' or you prefer to use a full word such as 'count' then that is fine also.

There is NO difference between:

for(i=0;i<100;i++)
example_array = i;

And

for(count=0;count<100;count++)
example_array[count] = count;

i is jsut the common shorthand variable for numeric values.

In CoDScript, the '.size' is the current count of contents inside an object.
So if you array had 100 items, then your arrays size would be 100.

Array = [];

Is a declaration to create an array.
When creating a variable, we did:

myVariable = value;

With arrays, we use the square brackets instead of the value.
An array is just a collection.
----------------

A good example for an array is playing cards.
Cards are collected and kept in the box.

box_of_cards = [];
We currently have an empty box of cards.

box_of_cards.size = 0. (There are NO cards in the box)
box_of_cards[ box_of_cards.size ] = "Ace of Spades"
So: box_of_cards[0] = "Ace of Spades"

box_of_cards.size = 1. (There is ONE card in the box)
box_of_cards[ box_of_cards.size ] = "Two of Spades"
So: box_of_cards[1] = "Two of Spades"

Once we have all 52 cards back in the box, we can now print them all out:

Code: Select all

for(counter=0 ; counter<box_of_cards.size ; counter++)
   iprintln("The first card is: " + box_of_cards[counter]);

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

Posted: May 4th, 2011, 6:09 am
by megazor
given an array of 30 random integers which range is 0-9:

Code: Select all

array = [];
for(i = 0; i < 30; i++)
          array[i] = randomInt(10);
you need to learn how many array items contain the number 5. you will have to use an if and another variable (numeric one, for counting how many times '5' repeats).

what you know for now is enough to solve that.

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

Posted: May 4th, 2011, 4:04 pm
by Ryan
megazor wrote:what you know for now is enough to solve that.
je pense, que non...

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

Posted: May 4th, 2011, 4:18 pm
by Rezil
Yes you do, it's not that difficult.

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

Posted: May 4th, 2011, 5:00 pm
by Ryan
i had forgotten modulus lol...

Code: Select all

if(i%5==0)
{
	iprintln(array[i]);
}

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

Posted: May 4th, 2011, 5:29 pm
by Rezil
Wrong, this doesn't work at all. You need to print HOW MANY 5 are present in the array.
Also, modulus won't work because 0%5=0 and 5%5=0 as well. Try again. :)

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

Posted: May 4th, 2011, 6:44 pm
by Ryan

Code: Select all

array = [];
for(i = 0; i < 30; i++)
            array[i] = randomInt(10);
            if(i%5==0 && i!=0 || 5);
			            {
			                       	return i;
			            }

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

Posted: May 4th, 2011, 7:15 pm
by Rezil
Seriously dude, it looks to me like you have no clue what you're doing. Modulus returns the remainder(what's left what you divide a number) of the division. So, 12%3 equals zero because 12 can be evenly divided into parts of 3. On the other hand 87%10=7 because 7 is what's left when you divide 87 into parts of 10. So now you have to think how you can use modulus for this exercise. Or if modulus is even the appropriate method to use.

Next, the keyword return is used when you want a function to return a value. Consider this code:

Code: Select all

main() //start of every program
{
	result = sumOf(3, 5);
}

sumOf(x, y) //our custom function
{
	sum = x+y;
	return sum;
}
You can interpret sumOf(x, y) as a regular mathematical function: f(x, y) = x+y. So in our example, result will be 8 because the function sumOf returns whatever the variable sum is. The variable sum takes the two parameters - x and y - and adds them together.

Third, reread my post above again. You have to get the AMMOUNT of fives, not the index of the array, at which these fives are located. Understood?

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

Posted: May 4th, 2011, 8:18 pm
by Ryan
i'm giving up with this one i dont know what youre demanding of me really... i've read through everything from page 4 and theres not anything similar to that i've learnt before... dont think i didnt try it and just couldnt be bothered wtih the effort it takes to to do it... i researched but i dont know how i can filter the amounts of 5s in there... maybe you do expect me to know this cos youre geniuses and mathematics professionals i'm certainly not and i'm just trying to learn something which is quite hard for me but you dont seem to have any patience anymore...

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

Posted: May 4th, 2011, 8:38 pm
by Rezil
This has very little to do with math and more with you understanding how coding works. You have to go through an array(shown before at least twice) using a for loop, then check if the value at that particular index in the array is a 5. If it is, increase your counter by 1. At the end of the loop, print out how many times you found a 5.

Code: Select all

array = []
for(i=0;i<30;i++)
        array[i] = randomInt(10);
counter = 0;
for(i=0;i<array.size;i++)
        if(array[i]==5) counter++;
iprintln(counter);
[/size]

7 lines of code. 4 for the actual solution part. It's not difficult, you just have to think(and know what each type does and what data it stores/how it stores it).

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

Posted: May 4th, 2011, 8:48 pm
by Ryan
i would've never come up with that... i'm trying to learn this but you guys are surely naturally better at thinking logically and youre used to this coding stuff... it seems easy to you whereas i'm struggling like fuck with it... i've been thinking about quitting but i dont wanna give up that easily thats queer tbh... so if you guys can bring along a bit more patience maybe it will pay off and youll experience some progress on my part which should trigger satisfaction on your part as your teaching work was efficient :)

the guy to give me the next exercise <should you decide to continue this nerve-thieving scripting topic> should please consider my exorbitantly low scripting level and choose his exercise thoughtfully since i'm a crappy scripter as you might notice :P