Raised This Month: $32 Target: $400
 8% 

Solved title


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 07-13-2021 , 13:05   title
Reply With Quote #1

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
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 07-14-2021 at 12:53.
kww is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 07-13-2021 , 15:59   Re: title
Reply With Quote #2

-- 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
jimaway is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-13-2021 , 20:37   Re: title
Reply With Quote #3

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.
__________________

Last edited by Bugsy; 07-13-2021 at 20:38.
Bugsy is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 07-14-2021 , 09:52   Re: title
Reply With Quote #4

how can be -- replaced by ++ in provided code?
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 07-14-2021 at 09:52.
kww is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-14-2021 , 09:58   Re: title
Reply With Quote #5

They both work the same way, the value just goes in the opposite direction.
__________________
Bugsy is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 07-14-2021 , 12:47   Re: title
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
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? 
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 07-14-2021 at 12:52.
kww is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-14-2021 , 22:50   Re: title
Reply With Quote #7

It depends on what you are doing and how you are using iAliveCount. The first one counts down and the second one counts up.
__________________
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:01.


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