Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting value of variable #3

Open
Jack10270 opened this issue Oct 17, 2022 · 6 comments
Open

Setting value of variable #3

Jack10270 opened this issue Oct 17, 2022 · 6 comments
Labels
help wanted Extra attention is needed

Comments

@Jack10270
Copy link

Hi this request for adding variable support to plugin

When user types expression sender can set value of variable:

(Sender) /calc x + 1
(Server) Enter value for variable x:
(Sender) 3
(Server) x + 1 = 4 where x = 3

(Sender) /calc x + 1
(Server) Enter value for variable x:
(Sender) pi / 4
(Server) x + 1 = 1.7 where x = 0.7

For this cyou can use await-std to be done easy (code adapted from https://github.com/SOF3/await-std-examples/blob/master/BanHammer/src/SOFe/BanHammer/Main.php)

$expr = implode(" ", $args);
Await::f2c(function() use($sender, $expr) : Generator{
	try{
		$values = [];
		foreach(expr variables as variable){
			$sender->sendMessage("Enter value for variable "  + $variable);
			$value = $std->consumeNextChat($sender);
			$values[variable] = $value;
		}

		evaluate expression using $values
	}catch(QuitException){
		// do nothing if $sender quit
	}
});
@NhanAZ
Copy link
Member

NhanAZ commented Oct 18, 2022

This issue is related to the math expression parsing library I am using on this plugin
I think you should open an issue at https://github.com/Muqsit/arithmexp
Their library doesn't seem to support solving equations yet

@NhanAZ NhanAZ added the help wanted Extra attention is needed label Oct 18, 2022
@Jack10270
Copy link
Author

Hi sir,,in the repository arithm exp in readme there is this code I think for allow to add variables

$expression = $parser->parse("x + y");
var_dump($expression->evaluate(["x" => 2, "y" => 3])); // int(5)
var_dump($expression->evaluate(["x" => 1.5, "y" => 1.5])); // float(3)

@NhanAZ
Copy link
Member

NhanAZ commented Oct 19, 2022

It doesn't work as you think.
I opened an issue on his library
You can see here: Muqsit/arithmexp#12

@Jack10270
Copy link
Author

@NhanAZ I mean equation substitution, equation solver will different thing yes

If I will give equation a + b and also give value for a and b, this is variable substitution
To do this the plugin will replace a with 3 and b with 4 and do calculation

If I will give equation a + bx and ask to find value of x, this is equation solving (solve for x)
To do this the plugin will do like "Let y = a + bx" or if its quadratic a(x^2)+bx+c the plugin will do like "Let a(x^2)+bx+c=0"

But it will also be good to have equation solver but my intend here was variable substitution

@NhanAZ
Copy link
Member

NhanAZ commented Oct 23, 2022

(Sender) /calc x + 1
(Server) Enter value for variable x:
(Sender) 3
(Server) x + 1 = 4 where x = 3

Why don't you use something like this?

(Sender) /calc 3 + 1
(Server) Result: 4

@NhanAZ
Copy link
Member

NhanAZ commented Jul 12, 2024

(Sender) /calc x + 1
(Server) Enter value for variable x:
(Sender) 3
(Server) x + 1 = 4 where x = 3

Why don't you use something like this?

(Sender) /calc 3 + 1
(Server) Result: 4

After about 2 years I realized my question was stupid :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants