Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-10-2005, 10:03 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
The variable "i"

There seems to be great confusion with this variable. I spoke with CheeToS about it, and it seems not even he is certain. I suppose no one has asked stefan about it (( )). So, I guess we could have an open discussion on it.


So...

Is "i" a global variable which could/does conflict with other variables?


EDIT:


In a for loop, it is said that a this. variable would make it slower, and it is rather recommended to use "i" alone. But, it is also said that "i" conflicts with other variables. So, I think it would be best to find the true answer.
Reply With Quote
  #2  
Old 06-10-2005, 10:05 PM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
The behavior of any variable without a prefix is undetermined. Use temp.i.
Reply With Quote
  #3  
Old 06-10-2005, 10:08 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Rick
The behavior of any variable without a prefix is undetermined. Use temp.i.

That is not the question at hand.


EDIT:

It is rather pertinent, but temp.i is GS2, and I'm speaking of the variable in general.

Last edited by Gambet; 06-10-2005 at 10:21 PM..
Reply With Quote
  #4  
Old 06-10-2005, 10:23 PM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
Quote:
Originally Posted by Gambet
In a for loop, it is said that a this. variable would make it slower, and it is rather recommended to use "i" alone.
Where did you get the silly notion that this.i is any slower than i?
Reply With Quote
  #5  
Old 06-10-2005, 10:28 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
From a source that would wish to be kept anonymous.
Reply With Quote
  #6  
Old 06-10-2005, 10:33 PM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
Quote:
Originally Posted by Gambet
From a source that would wish to be kept anonymous.
Why? That is pretty stupid.
Reply With Quote
  #7  
Old 06-10-2005, 10:36 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Yes, it is, but I respect this persons wish to remain anonymous.
Reply With Quote
  #8  
Old 06-10-2005, 10:54 PM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
I do not think using the this. prefix will cause a speed problem. Perhaps the mystery person believes using this. is a waste of memory, because it saves a loop variable to each individual NPC for no reason.

The only problem from using i is especially apparent in GS2. If you are calling a function inside another function, and they are both using the i loop variable, this will screw up the scripts. I think temp.i is better to use for this reason. I would like someone to explain the temp. prefix further though.
__________________

Reply With Quote
  #9  
Old 06-10-2005, 11:03 PM
CheeToS2 CheeToS2 is offline
That Guy
CheeToS2's Avatar
Join Date: Dec 2001
Location: Seattle, WA
Posts: 2,528
CheeToS2 will become famous soon enough
Send a message via AIM to CheeToS2
I said it to him; I told him that it is supposedly slower, because I recalled somebody else telling me that. I did not know if (or why) it was true or not. Sorry for the confusion

Anyway, this was discussed on #gscript on IRC for a little while. Here's a log:


<CheeToS> there is some confusion about using the variable "i" in for loops
<Jacco> There is?
<fry> there always is confusion
<VeloxCruentus> i = global var. They conflict with other NPCs.
<CheeToS> some say you should use this.i to avoid conflicts
<Rick> VeloxCruentus: four years ago
<fry> yep, non this. vars don't even work in gani scripts
<Bennity> How did the variable i come along anyway
<Bennity> It seems to be used for temp things
<Rick> iterator
<fry> it's small
<Jacco> integer?
<Jacco> oh.
<fry> and that
<Bennity> ah
<CheeToS> what is your opinion, Rick?
<Bennity> I thought it stood for something
<Rick> my opinion is to use temp.i
<CheeToS> lol
<fry> same here
<CheeToS> without GS2
<Bennity> In fact, there is a thread on the Graal forums from months and months ago about the use of i
<Rick> still, temp.i
<Bennity> and what it means
<Jacco> there's a temp.i?
<Jacco> I think all single-letter variables should be declared temp.
<ben> this.i only if sleep in loop.
<ben> kai smacks you if sleep in loop.
<ben> -> no this.i
<Jacco> lol
<Jacco> I sleep in the loop.
<ben> CheeToS: How else is it going to get screwed up?
<ben> Hm. Perhaps if you call a function that also modifies i.
<ben> temp.i wins I suppose.
<fry> other scripts using i at the same time
<Rick> ben: aye
<CheeToS> velox says he has had problems with other level NPCs changing i
<ben> Rick: Is temp.i local to the stack frame?
<fry> but that's not possible so wooh
Reply With Quote
  #10  
Old 06-11-2005, 01:10 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
unprefixed variables are shared between all scripts. It is unwise to rely on them retaining their values between frames.
this. variables are specific to the script. Their values will be constant between frames, but you don't need that to be the case for simple iterators
temp. variables are specific to each execution of the script in which they are called, like local vars in C. They should be used if you need to use recursion, or if you think you might use vars with the same name concurrently.
__________________
Reply With Quote
  #11  
Old 06-11-2005, 01:53 AM
Benm00t Benm00t is offline
I made a tree!
Benm00t's Avatar
Join Date: Jul 2003
Location: The Intarwebbernetwork!
Posts: 987
Benm00t is on a distinguished road
Quote:
Originally Posted by CheeToS2
I said it to him; I told him that it is supposedly slower, because I recalled somebody else telling me that. I did not know if (or why) it was true or not. Sorry for the confusion

Anyway, this was discussed on #gscript on IRC for a little while. Here's a log:

*Log*
So the conversation was about "this.". Ah... I don't think I got that at the time.
__________________
Lag is a good thing. Only those without it complain.

~ Ben
Reply With Quote
  #12  
Old 06-14-2005, 12:56 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
In old scripting:
On serverside variables without prefix are only valid inside the same script (npc script, weapon script, class script), on clientside they are "global".

New scripting:
All variables without prefix are global, except function parameters which are automatically made temp. variables. It is planned that there will be an option to make all variables without prefix temp. variables. That option will not be enabled by default because it could break scripts, since in the old scripting engine such variables are often used to pass parameters to functions (although this. variables are better for that if you want to pass parameters to functions inside other scripts/classes).
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.