DBDude221
|
  |
| Joined: 31 Jan 2010 |
| Total Posts: 74 |
|
|
| 18 Apr 2013 05:46 AM |
Hiya. Still pretty new to the world of programming.
Lets say I had a function:
function f(x) return x^2+6x-4 end
Is there any way to convert x^2+6x-4 into a string?? Not the actual answers that satisfy f(x), but the expression itself.
So it would become "x^2+6x-4"
Is this possible without declaring a new variable? |
|
|
| Report Abuse |
|
|
1WOOF1
|
  |
| Joined: 03 May 2009 |
| Total Posts: 20682 |
|
| |
|
DBDude221
|
  |
| Joined: 31 Jan 2010 |
| Total Posts: 74 |
|
|
| 18 Apr 2013 06:00 AM |
| Unless theres another way around it, the problem what that is as soon as you call f(x), "x" is evaluated and since the function is designed to return the value at x, it just spits out a number |
|
|
| Report Abuse |
|
|
josh50000
|
  |
| Joined: 29 Nov 2009 |
| Total Posts: 697 |
|
|
| 18 Apr 2013 06:04 AM |
Unless you want to the change the calculation while the game is running, the easiest way would be to:
function f(x) return "x^2+6x-4" end |
|
|
| Report Abuse |
|
|
josh50000
|
  |
| Joined: 29 Nov 2009 |
| Total Posts: 697 |
|
|
| 18 Apr 2013 06:10 AM |
Or did you want:
function f(x) return x.."^2+6"..x..-4" -- x in the calculation becomes defined from the function arg. end |
|
|
| Report Abuse |
|
|
josh50000
|
  |
| Joined: 29 Nov 2009 |
| Total Posts: 697 |
|
|
| 18 Apr 2013 06:12 AM |
| x.."^2+6"..x.."-4" -- missed a Speech mark |
|
|
| Report Abuse |
|
|
DBDude221
|
  |
| Joined: 31 Jan 2010 |
| Total Posts: 74 |
|
|
| 18 Apr 2013 06:14 AM |
| Yes, thanks. Thats exactly what I needed. |
|
|
| Report Abuse |
|
|