Page MenuHomeFeedback Tracker

Add a Integer++ (Integer = Integer + 1) command to the game
New, WishlistPublic

Description

Currently you need to do this to get a number one higher:

_i = _i + 1;

but that just shows that SQF is missing an important feature to make code readable and easy to get inside!
im working in a software company and if i need to setup any counter i would, will and are not allowed to use "variable = variable + 1;" as it breaks codestyle heavily ...

so there should be a "_i++" (and also an "_i--") for good code reading and compatibility to many other languages.

thx for your service
X39

Details

Legacy ID
1729656565
Severity
None
Resolution
Open
Reproducibility
N/A
Category
Scripting
Steps To Reproduce

Use this weird looking code:
{

_i = 0;
while {_i < 20} do
{
   _i = _i + 1;
   sleep 1;
};

}

and now check out how good it would look with the ++ operator:
{

_i = 0;
while {_i < 20} do
{
   _i++;
   sleep 1;
};

}

Event Timeline

X39 edited Steps To Reproduce. (Show Details)Dec 19 2013, 10:50 PM
X39 edited Additional Information. (Show Details)
X39 set Category to Scripting.
X39 set Reproducibility to N/A.
X39 set Severity to None.
X39 set Resolution to Open.
X39 set Legacy ID to 1729656565.May 7 2016, 5:39 PM

Yes please and while you at that please add += like you did with config arrays and -=

X39 added a subscriber: X39.May 7 2016, 5:39 PM

That specific syntax won't be possible.

It'd have to be

inc "_i";

X39 added a comment.Feb 19 2014, 4:43 PM

so where you got your nice sweet knowledge from?
try any other language like c++ for exmaple

im pretty sure it is possible

X39: That's because you don't know SQF.

X39 added a comment.Feb 19 2014, 4:53 PM

i promise you that it is possible
also
i got knowledge about SQF my friend
but seems like you dont got any knowledge in programming general

X32: Yet you keep claiming it's possible with the traditional syntax, while it's not.

If you knew SQF you'd know that the syntax _i++ is impossible. It's down right senseless in SQF.

X39 added a comment.Feb 19 2014, 5:05 PM

"Add a Integer++ (Integer = Integer + 1) command to the game"
read the title ...
its about adding the ++ syntax because its some sort of industrial standart (missleading ... its more that its in nearly ALL programming languages used by the industry)

also it would be possible with SQF:
just try it in your debuger:

_var1 = 1; _var2 = 2; hint str (_var1+_var2);

this code will still compile and work like expected
also try this:

  _var+ = 12;

_var+ is not a valid variable name meaning that you get a script error
so:
_var++ can be assumed as command structure where "_var" is the parameter and "++" the command

but yeah
youre right
i dont know anything about SQF
the only thing that this command would require is that the parameter is now left and not right

X39: "the only thing that this command would require is that the parameter is now left and not right"

And THAT is EXACTLY why it's not possible in SQF.

SQF is strictly expression based. The "commands" are operators, which can be either, nullary, unary or binary (except for = which is a special construct).

_var++ makes as little sense as 5 +;

You cannot have a unary operator that takes only a left hand side operand.

And you couldn't make ++ an operator either, and do ++i, because + is already a unary operator, and ++_i is explicitly +(+(_i)). (Just like --_i is explicitly -(-(_i)) that is, negate negate _i)

Which brings me back to my first post.

inc "_i";

inc is unused, and it needs to be within strings, as if you used inc _i; and _i is 5, then _i evaluates to 5, and the expression would be inc 5; which makes no sense.

X39 added a comment.Feb 25 2014, 11:52 PM

yeah yeah stupit
check the set function you hero ...

@X39: Set is a BINARY operator. What's your fucking point?

So, a question outside the fiery argument...

_i = _i + 1 is the same as _i++ in what you are saying. I understand this. However, what is wrong with keeping it how it is? It is its own language and has no obligation to reflect other languages, AND it works not just fine but perfectly.

As well, what about the event where you don't want to add just 1? What if you want 2, or 3.5? Or a variable that was defined as a number earlier?

The reason that SQF is easy to pick up is because it is literal and easy to read. There are no shortcuts, and thus no questions about the syntax other than structure. Why fix it if it isn't broken?

@KGrimes: Counters are used often in programming, and they usually increase by one.

That's why most languages support a simple incrementation (or decrementation) of variables.

eg. C++, C#, etc:
for (int i = 0; i < 10; i++)
{
}

Which is a lot faster to type than eg.
for (int i = 0; i < 10; i = i + 1)
{
}

And it's also prettier.
This is to specifically increment/decrement a variable by 1. If you need more, many languages also provide a += operator, so you don't have to type i = i + 5; but just i += 5; (assign the current value of i + 5 to i).

And even though the syntax for SQF has to be different than what you'll usually see in other languages, it still is faster to type eg. inc "_i";

And += can actually be added with the same syntax as you'd expect in other languages, albeit as a special construct, like the assignment operator (The assignment operator is the only operator in SQF that isn't technically an operator).

Thank you for clarifying. You're right, the +=/-= would accomplish what I challenged.

However, I still emphasize the fact that SQF NEEDS to be simple, which it is due to its straight-forward-ness. Otherwise, it will certainly take people longer to get used to the language let alone use it successfully. I understand you programmers are all about performance down to the hundredth of a millisecond, but frankly, that kind of optimization is no where near needed in this setting. In the event that it is, you definitely could have some better organization of your executions. This is not the place to sacrifice ease of use for performance.

I am not opposed to adding _i++ in the event that what is currently employed stays working as well.

@KGrimes: It's not about performance. It's about readability and easyness.
inc "_i"; is not a replacement for _i = _i + 1. It's an addition. People who don't want to use the easy way, can use the cumbersome way.

You cannot possibly argue that inc "_i" is easier to read than _i = _i + 1. As soon as you start expecting that knowledge from people is the time that the number of good missions drop in count.

@KGrimes: That's like saying a harvester is a bad solution just because people don't know how to use it.

inc "_i"; is far more readable than _i = _i + 1; or _i=_i+1; for that matter.

All I'm saying is the more material and more complexity that you require lay-users to know, the less you will see of them and from them.

X39 added a comment.Feb 26 2014, 6:56 PM

@KGrimes
just leave him alone in his small world ...
(think hes also one of those guys who thought "JAVA is a stupid idea and a giant security problem!")