AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved title (https://forums.alliedmods.net/showthread.php?t=333460)

kww 07-13-2021 13:05

title
 
can someone help me with equivalents of this snippets?
I can't understand how -- works
Code:

1) for(--iAliveCount; iAliveCount >= 0; iAliveCount--)
2) iDeadPlayers[i--] = iDeadPlayers[--iDeadCount]

Stolen from: https://forums.alliedmods.net/showthread.php?p=1469706

jimaway 07-13-2021 15:59

Re: title
 
-- is just -1.
if it's as a prefix the equation will be handled before the code, suffix will be handled after the code
Code:

new i = 1
// i is now 0
somebool[--i] = true

new y = 1
somebool[y--] = true
//y is now 0


Bugsy 07-13-2021 20:37

Re: title
 
PHP Code:

5
test 
p--

//test = 5 

PHP Code:

5
test 
= --p

//test = 4 

The value of p after the p-- or --p lines of code are executed is the same.

kww 07-14-2021 09:52

Re: title
 
how can be -- replaced by ++ in provided code?

Bugsy 07-14-2021 09:58

Re: title
 
They both work the same way, the value just goes in the opposite direction.

kww 07-14-2021 12:47

Re: title
 
Quote:

Originally Posted by Bugsy (Post 2752827)
They both work the same way, the value just goes in the opposite direction.

PHP Code:

/* so this:             */ for (--iAliveCountiAliveCount >= 0iAliveCount--)
/* can be replaced by:  */ for (new iiAliveCounti++) /* ? */
// am I right? 


fysiks 07-14-2021 22:50

Re: title
 
It depends on what you are doing and how you are using iAliveCount. The first one counts down and the second one counts up.


All times are GMT -4. The time now is 02:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.