mirror of
https://gitlab.com/niansa/pilang2.git
synced 2025-03-06 20:49:22 +01:00
Implemented asint for inc/dec
This commit is contained in:
parent
eb6e5c47d5
commit
8e61559f05
1 changed files with 11 additions and 3 deletions
|
@ -234,15 +234,20 @@ std::string cmd_append(std::vector<std::string> args) {
|
|||
return success;
|
||||
}
|
||||
std::string cmd_incdec(bool type, std::vector<std::string> args) {
|
||||
bool asint = false;
|
||||
//Check amount of arguments
|
||||
if (args.size() < 1 or args.size() > 2) {
|
||||
if (args.size() < 1 or args.size() > 3) {
|
||||
return badarguments;
|
||||
}
|
||||
// Get arguments
|
||||
auto argsit = args.begin();
|
||||
if (*argsit == "asint") {
|
||||
asint = true;
|
||||
argsit++;
|
||||
}
|
||||
std::string variablename = *argsit;
|
||||
float incby;
|
||||
if (args.size() == 2) {
|
||||
if (args.size() > 1) {
|
||||
argsit++;
|
||||
incby = std::atof((*argsit).c_str());
|
||||
} else {
|
||||
|
@ -257,7 +262,10 @@ std::string cmd_incdec(bool type, std::vector<std::string> args) {
|
|||
currval += incby;
|
||||
else
|
||||
currval -= incby;
|
||||
variables[variablename] = std::to_string(currval);
|
||||
if (!asint)
|
||||
variables[variablename] = std::to_string(currval);
|
||||
else
|
||||
variables[variablename] = std::to_string((int)currval);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue