The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Eval & Expressions
Author Message
Pestilence
Apprentice
*

Posts: 16
Likes Given: 3
Likes Received: 0 in 0 posts
Joined: Oct 2013
Reputation: 0



Post: #1
Eval & Expressions
Hey All. :)

Version: 08-01-2015 nightly linux debug

As permanently checking changelog. And people in irc says "every line is evaluated"

Can somebody confirm this ridiculous behaviour:

Code:
[function f_learn]
local.x 1
local.y 10
local.x += 1
local.y -= 5
sysmessage "<dlocal.x> <dlocal.y>" // Returns: "2 5"

local.x 1
local.y 10
local.x+=1
local.y-=5
sysmessage "<dlocal.x> <dlocal.y>" // Returns "1 10"

local.x 1
local.y 10
sysmessage <dlocal.x>+<dlocal.y> // Returns "1+10"

local.x 1
local.y 10
sysmessage <dlocal.x> + <dlocal.y> // Returns "1 + 10"

Just paste it in your sphere and run .f_learn

Looks like trusting and NOT using "eval" in expressions is totally biggest fault for scripting :D

IMHO:
Example #4 shouldn't work because there are spaces...
Example #3 SHOULD work because there are NO spaces and NO quotes
But most killing thing... #2 & #1... now I'm totally unsure can i really use "newgold -= 5000" or "newgold-=5000"

Update:

Code:
[function f_learn]
gold 1000
sysmessage "1000 -> <gold>" // 1000 -> 1000 (works)

gold += 1000
sysmessage "2000 -> <gold>" // 2000 -> 2000 (works)

gold+=1000
sysmessage "3000 -> <gold>" // 3000 -> 1000 (broken)

gold -= 1000
sysmessage "2000 -> <gold>" // 2000 -> 0 (works)

gold-=1000
sysmessage "1000 -> <gold>" // 1000 -> 1000 (broken)
(This post was last modified: 01-08-2015 02:35 PM by Pestilence.)
01-08-2015 02:12 PM
Find all posts by this user Like Post Quote this message in a reply
eberk
Apprentice
*

Posts: 2
Likes Given: 0
Likes Received: 2 in 1 posts
Joined: Aug 2014
Reputation: 0



Post: #2
RE: Eval & Expressions
local.x+=XXXX without space to equal symbol ( = ) i think sphere read it like "YYYY=XXXX" means YYYY for 'local.x+' and XXXX is value, so in your example can u check (for example #2)
Code:
local.x 1
local.y 10
local.x+=1
local.y-=5
sysmessage "<dlocal.x> <dlocal.y> <dlocal.x+> <dlocal.y->" //Now it should Returns "1 10 1 5"

and sysmessage command (#3,#4) i think it want string value so actually you have to do it like
Code:
local.x 1
local.y 10
local.temp = <dlocal.x>+<dlocal.y>
sysmessage <dlocal.temp>
or as you discuss u have to use "eval" experession before sysmessage command reads for string. like; <eval <dlocal.x>+<dlocal.y>>
01-08-2015 07:15 PM
Find all posts by this user Like Post Quote this message in a reply
Extreme
Grandmaster Poster
***

Posts: 1,141
Likes Given: 217
Likes Received: 90 in 77 posts
Joined: May 2012
Reputation: 20

SphereCommunity

Post: #3
RE: Eval & Expressions
Just use eval everywhere..
100% sure it will work

STEPS BEFORE CREATE A THREAD
- Check the revisions log;
- Use the search button and use the keywords of your problem;
- Check the WIKI;
- Create a thread.
01-09-2015 11:41 AM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes Extreme's post
Pestilence
Apprentice
*

Posts: 16
Likes Given: 3
Likes Received: 0 in 0 posts
Joined: Oct 2013
Reputation: 0



Post: #4
RE: Eval & Expressions
(01-09-2015 11:41 AM)Extreme Wrote:  Just use eval everywhere..
100% sure it will work

That's what I really started doing Big Grin
01-09-2015 12:38 PM
Find all posts by this user Like Post Quote this message in a reply
XuN
Sphere Developer
*****

Posts: 852
Likes Given: 102
Likes Received: 156 in 119 posts
Joined: Jul 2013
Reputation: 30



Post: #5
RE: Eval & Expressions
I'm not sure if I did understand this but this is my contribution:

- You should use local.bla += x and NOT local.bla+=x
- Values are stored in hex, so it doesnt matter if you use local.bla = <eval 8+2> and local.ble = <dlocal.bla> because they will be stored as '0a' anyways, so using evals to storage is a waste of cpu.
- Numerical strings SHOULD be eval'ed to output them
(This post was last modified: 01-11-2015 02:01 AM by XuN.)
01-11-2015 02:01 AM
Find all posts by this user Like Post Quote this message in a reply
[+] 2 users Like XuN's post
Pestilence
Apprentice
*

Posts: 16
Likes Given: 3
Likes Received: 0 in 0 posts
Joined: Oct 2013
Reputation: 0



Post: #6
RE: Eval & Expressions
Xun, My question was related only to #1
but having stuff like "attr=010" and then you see "color += 01", slightly messing, isn't?
01-11-2015 03:37 PM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)