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 11-30-2005, 11:06 PM
Raeiphon Raeiphon is offline
I never asked for this.
Join Date: Jun 2005
Posts: 855
Raeiphon is on a distinguished road
tiles[x,y] ?

I cant seem to get it to work.

HTML Code:
  //begin complex
  if (strequals(#v(tiles[playerx,playery]),127 + 15 * 16)) {
    setplayerprop #c, command;
  }
It's meant to set the player chat to "command" whenever you fire the weapon on a normal grass ground, and yes, it is a shovel. I cant think of any other way to do this, and my commands RTF doesnt have tiles[x,y] in it. Is there another one I can get which is upadted?
__________________

I hope for nothing. I fear nothing. I am free.
Reply With Quote
  #2  
Old 12-01-2005, 12:25 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
"127 + 15 * 16" is being treated as a string, not being evaluated.

Try #v(127 + 15 * 16).
__________________
Skyld
Reply With Quote
  #3  
Old 12-01-2005, 02:16 AM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
Quote:
Originally Posted by Skyld
Try #v(127 + 15 * 16).
Or you can just do
tiles[playerx,playery] == 127 + 15 * 16
although, it's probably better to just use 367 instead of 127 + 15 * 16
__________________
Reply With Quote
  #4  
Old 12-01-2005, 05:50 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by ZeLpH_MyStiK
Or you can just do
tiles[playerx,playery] == 127 + 15 * 16
although, it's probably better to just use 367 instead of 127 + 15 * 16
Each of the numbers in that statement must have some significance, so it's probably better to leave it in a way you can understand it, rather than use one big magic number :x
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #5  
Old 12-01-2005, 06:59 AM
Raeiphon Raeiphon is offline
I never asked for this.
Join Date: Jun 2005
Posts: 855
Raeiphon is on a distinguished road
Still doesnt work, i've tried it with the #v on both, refuses to work =/

EDIT:
odd, It works now, but the normal grass code is 2047 for some reason, is there any way to verify that?
__________________

I hope for nothing. I fear nothing. I am free.

Last edited by Raeiphon; 12-01-2005 at 07:09 AM..
Reply With Quote
  #6  
Old 12-01-2005, 08:14 AM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
Quote:
Originally Posted by ApothiX
Each of the numbers in that statement must have some significance, so it's probably better to leave it in a way you can understand it, rather than use one big magic number :x
ah, that's what comments are for okiesmoke =p
__________________
Reply With Quote
  #7  
Old 12-01-2005, 09:06 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Why don't you make the specific tiles in an array?
It'd be alot easier my friend. :0
Reply With Quote
  #8  
Old 12-01-2005, 12:49 PM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
Quote:
Originally Posted by xAndrewx
Why don't you make the specific tiles in an array?
It'd be alot easier my friend. :0
Why would he need it in an array? He only has one tile to check for =\
__________________
Reply With Quote
  #9  
Old 12-01-2005, 03:16 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by ZeLpH_MyStiK
ah, that's what comments are for okiesmoke =p
comments?! Who need's 'em! :P

Real scripters script everything on one line and have no comments!1!!1
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #10  
Old 12-01-2005, 05:44 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by ZeLpH_MyStiK
Why would he need it in an array? He only has one tile to check for =\
I'm still saying using an array would be alot easier.
Reply With Quote
  #11  
Old 12-01-2005, 06:03 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by xAndrewx
I'm still saying using an array would be alot easier.
Explain this theory.
__________________
Skyld
Reply With Quote
  #12  
Old 12-01-2005, 06:25 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
It'd be alot easier, if you ever wanted to add more then just one tile. Future planning
Reply With Quote
  #13  
Old 12-01-2005, 06:46 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
But that doesn't make it any easier to do in the present?
__________________
Skyld
Reply With Quote
  #14  
Old 12-01-2005, 07:18 PM
Fox1545 Fox1545 is offline
Registered User
Join Date: Jul 2004
Posts: 78
Fox1545 is on a distinguished road
Quote:
Originally Posted by ZeLpH_MyStiK
although, it's probably better to just use 367 instead of 127 + 15 * 16
[...]
ah, that's what comments are for okiesmoke =p
It is not. Ideally you would use a constant like this.TILE_FOOBAR = 127 + 15 * 16;, or at least a function like getTileFromTileset(x, y) if the tile is not really namable. Putting magic numbers and then commenting them is not exactly elegant, and the foo + bar * 16 form at least adds a lot of editability.

Quote:
Originally Posted by Raeiphon
odd, It works now, but the normal grass code is 2047 for some reason, is there any way to verify that?
Mouseover it in the tile selection frame, and you are going to see the coordinates at the bottom of it. The `code' is x + 16 * y, I think.
Alternatively, write a script to output the `code' of the tile below your mouse cursor or something.

Quote:
Originally Posted by xAndrewx
It'd be alot easier, if you ever wanted to add more then just one tile. Future planning
Because it is totally cool to go against generally accepted programming practice for no reason at all.
Reply With Quote
  #15  
Old 12-01-2005, 07:36 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
O-o Haha, all this time I thought it was x + y * 16.

Anyway, I think the original poster is still trying to use #v() somewhere in the equation. You DO NOT need #v() ANYWHERE. The correct way to do it is (tiles[x,y] == number)

And I agree with Fox. Plus, an array with one value isn't an array..
However, I think you should be able to read a variable that's not an array with var[0].
PHP Code:
function onCreated() {
  
this.cookies 7;
  
chat this.cookies[0];

Reply With Quote
  #16  
Old 12-01-2005, 10:02 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by Yen
And I agree with Fox. Plus, an array with one value isn't an array..
However, I think you should be able to read a variable that's not an array with var[0].
PHP Code:
function onCreated() {
  
this.cookies 7;
  
chat this.cookies[0];

PHP Code:
function onCreated()
{
  
rname "LINDA";
  echo(
rname SPC rname[0]);

... produces "LINDA LINDA".
__________________
Skyld
Reply With Quote
  #17  
Old 12-01-2005, 11:35 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
The house system on Versus wouldn't read owner[0] if 'owner' didn't have 2 or more entries, so I had to add "(npc-server)"...
Reply With Quote
  #18  
Old 12-02-2005, 12:27 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
y * 16 + x
y * w + h is how one dimensional arrays are indexed with x and y parameters. (it makes sense, too, after you have one row done, you will add 1 to y, which makes the next row (1*16) = 16 + x)
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #19  
Old 12-02-2005, 01:21 AM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
Quote:
Originally Posted by Fox1545
It is not. Ideally you would use a constant like this.TILE_FOOBAR = 127 + 15 * 16;, or at least a function like getTileFromTileset(x, y) if the tile is not really namable. Putting magic numbers and then commenting them is not exactly elegant, and the foo + bar * 16 form at least adds a lot of editability.
Why would you want to waste cputime calculating a constant?
__________________
Reply With Quote
  #20  
Old 12-02-2005, 02:33 AM
Fox1545 Fox1545 is offline
Registered User
Join Date: Jul 2004
Posts: 78
Fox1545 is on a distinguished road
Quote:
Originally Posted by ZeLpH_MyStiK
Why would you want to waste cputime calculating a constant?
Because CPU time is less expensive than scripter time.
Reply With Quote
  #21  
Old 12-02-2005, 02:50 AM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
Quote:
Originally Posted by Fox1545
Because CPU time is less expensive than scripter time.
If it takes you several hours to perform that calculation, maybe. But then again, if it took you several hours, then you should not script at all.
__________________
Reply With Quote
  #22  
Old 12-04-2005, 02:01 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Fox1545
Because CPU time is less expensive than scripter time.
Wrong answer.

You use CPU time calculating a constant because each of the numbers in the calculation represents something important. Think about it, if you were going to change the tile you wanted to check for in the future, would you rather change one number in an equation, or try to remember the equation you used, and then put the appropriate number back in to it?

The only reason you would use a constant in this case, would be because you are saving yourself from typing (and the CPU calculating) that more than once.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #23  
Old 12-04-2005, 02:26 AM
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 end result is probably stored as 367 in the bytecode anyway.
Reply With Quote
  #24  
Old 12-04-2005, 02:33 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Rick
The end result is probably stored as 367 in the bytecode anyway.
Hmm, in an interpreted scripting language? I doubt it :x
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #25  
Old 12-04-2005, 02:43 AM
Fox1545 Fox1545 is offline
Registered User
Join Date: Jul 2004
Posts: 78
Fox1545 is on a distinguished road
Quote:
Originally Posted by ApothiX
Wrong answer.
No, I just assumed you guys would be clever enough to understand it without be giving multiple paragraphs of answers.

The microseconds it takes the compiler to calculate the number are not even worth mentioning. Assuming that Stefan does not do constant folding at compile time, the microseconds it takes the interpreter to calculate the number are still not enough to worry about it.

We want to write down the whole formula in the script because the trouble I will have with recalculating the number each time I am going to change the tile refering to severly outweights the CPU's trouble calculating it for me. This is about what you said, I think.

But we still want to use a variable holding the number for us instead of putting it down where we use it and just commenting it for its meaning.

We could consider the variable lookup that is going to take a lot more performance, over time then the CPU's calculation will, because gscript does not have C++-style const variables and cannot substitute the variable references with the number at compile time. This could be as simple as having a numeric variable index and using it to index some variables array, but as it is possible to form variable names using the this.("foo" @ "bar) notation at runtime, I assume that we will still have to do a string-search in the this object at runtime.

But I do not care because it is gscript's job to take care of stuff like that. I gladly make that negligible sacrifice to gain more maintainability.

You generally do not want to have random magic numbers in your code. Often, the meaning will not be immediately obvious to someone trying to do maintain your script, either someone else in your NAT, or yourself a week later. This is why we give the number a name, using a variable. This is why we use names in general, we should not make an exception here. Using a comment would only be an ugly workaround, harder to maintain and no one bothers to write comments in production code anyway when code could be self-documenting.

Also, according to Don't repeat yourself, I want to be able to change the constant's value in a single place in my system without having to search my whole script or even set of scripts for uses of that particular equation. I am likely to forget to change it in one place, leading to annoying bugs.

There is more discussion regarding magic numbers on that other wiki.

Quote:
Hmm, in an interpreted scripting language? I doubt it :x
GScript is compiled to bytecode. Why would there not be constant folding?
Reply With Quote
  #26  
Old 12-04-2005, 03:54 AM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
If a tiny little ant bit you, it probably would not hurt. If hundreds and thousands of ants bit you...well you know what'd happen.
__________________
Reply With Quote
  #27  
Old 12-06-2005, 06:02 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Fox1545
No, I just assumed you guys would be clever enough to understand it without be giving multiple paragraphs of answers.
If you don't want to explain your post, then why bother explaining at all? The reason for using the equation rather than a constant number has nothing to do with the 'expense' of the scripter's time.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #28  
Old 12-08-2005, 03:27 PM
Fox1545 Fox1545 is offline
Registered User
Join Date: Jul 2004
Posts: 78
Fox1545 is on a distinguished road
Quote:
Originally Posted by ApothiX
If you don't want to explain your post, then why bother explaining at all?
I did not say I do not want to. I said I assumed it would not be necessary, perhaps because I spend too much time in #gscript.

Quote:
The reason for using the equation rather than a constant number has nothing to do with the 'expense' of the scripter's time.
Yes it has.
I am so winning this argument.
Reply With Quote
  #29  
Old 12-08-2005, 05:32 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Fox1545
I did not say I do not want to. I said I assumed it would not be necessary,
Your post was extremely vague, if you do not explain, then no one will understand what you meant.

Quote:
Originally Posted by Fox1545
perhaps because I spend too much time in #gscript.
Is that supposed to raise your intelligence-rating? For the record, I am an active member in the #gscript community, and I have not yet seen you actively participating in discussions in the channel.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #30  
Old 12-09-2005, 09:32 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
It doesn't matter that it's being calculated.
What matters is how often it's being calculated.

If it's once, Sure, don't bother to pre-calculate.

If it's hundreds of times a second, I recommend pre-calculating it.

Just put it in a variable at creation, and use that in the script. That will garentee it's only calculated once.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #31  
Old 12-09-2005, 01:02 PM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
It is being calculated slightly more than once every 0.05 seconds.
__________________
Reply With Quote
  #32  
Old 12-09-2005, 05:46 PM
Fox1545 Fox1545 is offline
Registered User
Join Date: Jul 2004
Posts: 78
Fox1545 is on a distinguished road
Quote:
Originally Posted by ApothiX
Your post was extremely vague, if you do not explain, then no one will understand what you meant.
But I already explained it.

Quote:
Is that supposed to raise your intelligence-rating?
It is supposed to show why I assumed that the people around me were clever enough to understand my point without the long explanation.

Quote:
For the record, I am an active member in the #gscript community
Oh yeah? Well, I am a founding member of the #gscript community

Can we argue the scripter-time-expense part more?
Reply With Quote
  #33  
Old 12-09-2005, 05:58 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Fox1545
But I already explained it.
Yes, After I had told you you were wrong.

Quote:
Originally Posted by Fox1545
Oh yeah? Well, I am a founding member of the #gscript community
And I can tell by the content of your posts the reason why you're not active any more.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #34  
Old 12-09-2005, 09:07 PM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
For the record, I went ahead and benchmarked this crap because you are all to lazy.

For expressions of numbers versus a single number out of 26 runs:
13 times the expression was faster
13 times the single number was faster

For expressions/single numbers (if you don't understand why I now group these, go away, you are stupid) versus a constant variable look-up in 26 runs:
1 time the constant look-up was faster
25 times the expression was faster

Now we must figure out the meaning of these results:
First, I ran these through 10 consecutive 10000 iteration loops, meaning this is a very extreme case. Second, the difference in timing was thus;
For the first test:
-average difference: .04 seconds
-smallest difference: .01 seconds
-largest difference: .1 seconds
For the second:
-average difference: .2 seconds
-smallest difference: .017 seconds
-largest difference: .37 seconds

None of these numbers are substantial given the context. So it is apparent that giving Graal an expression versus a computed expression makes no difference (as it is bytecoded, I am told by several very reputable sources). It is also true that while giving an expression is more efficient versus using a constant concerning CPU time. However, as Fox has already clarified, using a constant for recurring data is very beneficial to saving programmer time. If you do not understand this, you require more experience. When you use expressions only, and you need to change all instances of that expression in a complex code, then you will be thankful to have used a constant. This is governed by the inevitability that you will miss some instances and require debugging time just to change recurring data.

To summarise, using number expressions will benefit you by removing the abstractness of magic numbers(granted you want this). Using a constant to store recurring data in code will benefit you in programmer lookup and debugging time when you need to change that data.
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial

Last edited by Dach; 12-09-2005 at 09:32 PM.. Reason: Now with non-estimated stats!
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 08:25 PM.


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