The 'QuakeC lessons' thread[prev. help with script teleport]

Have questions about CoD/UO mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

SubGunner
CJ Wannabe
CJ Wannabe
Posts: 17
Joined: February 16th, 2011, 10:41 pm

Re: help with script teleport

Post by SubGunner » May 1st, 2011, 2:44 pm

Read through the thread. If he wanted to simply copy and paste someone elses work, the thread would've finished on the first page.
Well excuuuuuuse me!

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: help with script teleport

Post by Rezil » May 1st, 2011, 3:30 pm

Ryan wrote:why is it myVariable or can it be anything actually?

why is it myVariable = ""; what do the "" do there

why is it for(;;) what do the ;; do there

why is it i=0; i<15 what is i?

how do you print out this stuff then? rezil asked to make players able to see this then...
1.) It can be anything, something like a_z_gggg_EGAHEAEHAGWA_LOLrofl = "" would work equally well, you'd just have a really hard time using the variable later on. That's why simple, yet descriptive names are encouraged.

2.) the "" tells the script you want to make myVariable a string(basically letters and numbers, sort of like a sentence). If you were to make myVariable = 0, that would tell the script that it's an integer(a 'whole' number: 0, 1, 2, -5, -6, 54 etc.)

3.) Read drofders tut again, that's an infinite loop.

4.) Again, drofders tut, that's a finite loop that loops for 15 cycles, i is just the name of the variable, anything could've been used but the general practice is to use letters from i onward in finite loops.

5.) The same way you printed it out before, iPrintLn and iPrintLnBold
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » May 1st, 2011, 5:04 pm

and why is it i = 0? and could it have been rezilhelpsscriptinglol = 0 too?

maybe we should move on to easier tasks if there are easier tasks at all :P

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » May 1st, 2011, 6:38 pm

so if i put myVariable = ""; but later i put i it still works? how does it still know what variable it is related to then?

Rezil i like your exercises but this one was a bit hard for me :)

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: help with script teleport

Post by Drofder2004 » May 1st, 2011, 6:39 pm

For clarification 'i' is commonly used for INTEGERS. Variables can be anything you choose them to be (although, there are a few exceptions...)

The For Loop

Code: Select all

FOR( <declaration> ; <while> ; <statement> )
<declaration> = You can declare a variable here. (It is common to declare a integer for counting)
<while> = This section of the loop is what tells the loop when to end. (Most commonly, this will be the a LESS THAN statement)
<statement> = This is performed at the end of EVERY loop. (Usually to increment the counter)

The following two loops, are exactly the same:

Code: Select all

for( i = 0 ; i < 100 ; i++)
{
   iprintln(i);
}
 
 
i = 0;           /* <declaration> */
while( i < 100 ) /* <while> */
{
   iprintln(i);
   i++;          /* <statement> */
}
With the FOR loop, none of the fields are required, so the following, will also work (although pointless)...

Code: Select all

i = 0;             /* <declaration> */
for( ; i < 100 ; ) /* <while> */
{
   iprintln(i);
   i++;            /* <statement> */
}
And because no fields are required if you do "for(;;)", you are telling the loop, to not create a variable, to never end and to never perform an action.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: help with script teleport

Post by Drofder2004 » May 1st, 2011, 6:45 pm

Ryan wrote:so if i put myVariable = ""; but later i put i it still works? how does it still know what variable it is related to then?

Rezil i like your exercises but this one was a bit hard for me :)
If you create a variable called "myVariable" and then assign the value of "", you are simply creating a STRING variable with no value. You can then later use this variable to store string data.

So if I do

Code: Select all

myVariable = "";
anotherVariable = "This Is One ";
yetAnotherVariable = "Half Of A Variable";
I now have three STRING variables. One of them is empty.

I can then do:

Code: Select all

myVariable = anotherVariable + yetAnotherVariable;
iprintln(myVariable);
When I run that code, the game will print a message saying "This Is One Half Of A Variable".

Read slow and let us know if you're not following :D
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » May 1st, 2011, 6:49 pm

but if i put
myVariable = "";
do i have to put later on
for(myVariable = 0; myVariable < 10; myVariabe++)
or can i put
for(i = 0; i < 10; i++)

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: help with script teleport

Post by Drofder2004 » May 2nd, 2011, 12:10 am

Well, technically you could do that, but there are limited reasons to do it.
Take for example.

Code: Select all

main()
{
   i = 80;
   j = i + 20;
 
   for(i=0;i<j;i++)
   {
      iprintln(i);
   }
}
In the above example, you can see that the variable 'i' is given a value of 80.
I then declare a new variable called 'j' that I give the value of 'i' plus 20.

At this point in the script, I no longer need the value of 'i'. It is a variable that no longer has any use.
I can choose to recycle this variable and use it in the loop. Although this will save some (tiny amounts) of memory it will practically not change anything. I could just as easily use another variable in its place in the loop and it would make zero difference.

Now, for the sake of learning, it is safer and easier to simply use a new variable in the loop. This will help you avoid confusion and will also make error handling a lot easier.

To summarise:
No you do NOT have to use existing variables, you can use any variable you wish when creating your loops
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » May 2nd, 2011, 2:24 pm

alright thanks for your help guys... do you mind giving other exercises which i can now try?

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: help with script teleport

Post by IzNoGoD » May 2nd, 2011, 5:11 pm

Alright,
This one might be a bit hard for you, but you can always ask for some help:

Run a thread on every player after said player connects (use level waittill("connecting", randomvar); to put the player in the "randomvar") and make it display the distance between where a player starts pushing the use-key and where the player lets go of the use-key.

As said, this might be a bit steep, but practice makes perfect
LMGTFY!

Its not a glitch... Its the future!

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: help with script teleport

Post by megazor » May 3rd, 2011, 4:32 am

a little tip:

sElF uSeBuTtOnPrEsSeD()

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » May 3rd, 2011, 1:10 pm

KillerSam wrote:
Ryan wrote:alright thanks for your help guys... do you mind giving other exercises which i can now try?
Ok...how about.......


Print to the screen all the square numbers as far as 20x20


it should be displayed as follows to the user:

"5x5 is equal to 25"
"6x6 is equal to 36"

You should use a calculated value, using the loops you've used previously. If you need help or clarification, post back.
how can you make the script print the different values every time? like its not always 5x5 is equal to 25. 5 5 and 25 are variables that change with every round. but how do you let the scirpt know this? i just put what seems most logical to me.. again ive no idea how to do this and just guessed:

Code: Select all

for(i=0;i<21;i++)
{
	var = i * i;
	iprintln("(i)x(i) is equal to (var)";
	
	if(i>20)
	{
		wait 1;
		break;
	}
}

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » May 3rd, 2011, 1:26 pm

IzNoGoD wrote:Alright,
This one might be a bit hard for you, but you can always ask for some help:

Run a thread on every player after said player connects (use level waittill("connecting", randomvar); to put the player in the "randomvar") and make it display the distance between where a player starts pushing the use-key and where the player lets go of the use-key.

As said, this might be a bit steep, but practice makes perfect
pretend you know the words "hi" and "my name is". now translate this text for me:
Each market has its own regulations and little formality is needed. Contracts are made by verbal agreement. Brokers, who act as intermediaries between buyers and sellers, make notes of the essentials of the transactions made. On the basis of these essentials they issue so-called contract notes, which serve as written confirmations of commodity market transactions.

thats about the level of scripting i range between and the level of scripting required to solve your exercise...

edit: yeah sam i'm following everyhing clear thanks for your help mate, mind giving me more exercises? ig uess ill have to be advanced to do IzNoGod's one :P
Last edited by Ryan on May 3rd, 2011, 1:30 pm, edited 1 time in total.

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: help with script teleport

Post by Rezil » May 3rd, 2011, 1:31 pm

You can try that one when you've advanced quite a bit.
Also:

Code: Select all

for(i=0;i<21;i++)
        iprintln(i+"x"+i+" equals "+(i*i));
is about as optimal as it gets. :)

By the way Ryan, do you know how to test your code? As in, how to put it in a map script and make it run?

Try this:

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.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: help with script teleport

Post by Drofder2004 » May 3rd, 2011, 1:36 pm

Most of what I previously typed has been explained, but here is the answer to your question regarding the change of variable and how does it know it has changed. It all lies in the loop.
To read the entire function in Pseudocode would be:

1. Create a loop.
1a. Declare a variable called 'i' and give it value of zero
1b. Tell the loop to continue looping while the value of 'i' is less than 21.
1c. At the end of each loop do action 'i++' (add 1 on to the value of 'i')
2. Start Loop

3. Create a variable called 'var' and assign it the value of 'i' squared. (i = 0, therefore var = 0)
4. Print the message to screen (using current variable values)
5. End Loop - Add 1 to the value of 'i' (i now equals 1) - Repeat from (3).

3. Assign the varaible 'var' a value of 'i' squared (i = 1, therefore var = 1)
4. Print the message to screen (using current variable values)
5. End Loop - Add 1 to the value of 'i' (i now equals 2) - Repeat from (3).

(Many loops later)

3. Assign the varaible 'var' a value of 'i' squared (i = 20, therefore var = 400)
4. Print the message to screen (using current variable values)
5. End Loop - Add 1 to the value of 'i' (i now equals 21) - <While> condition is false! (21 is NOT less than 21)
6. Break Loop
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests