AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Instead of the loop (https://forums.alliedmods.net/showthread.php?t=245998)

yl2401 08-09-2014 23:56

Instead of the loop
 
Normal:
PHP Code:

for( new ii<maxi++ ) 

if max = 2, "i" had 1 and 2.

Opposite:
PHP Code:

for( new i=maxi>0i-- ) 

if max = 2, "i" had 0 and 1.

1 and 2, how to make it in the opposite?
THANK YOU!

fysiks 08-10-2014 02:58

Re: Instead of the loop
 
This question doesn't really make much sense. I think we have an XY Problem here.

Please explain, in detail, what you are actually trying to do.

yl2401 08-10-2014 05:21

Re: Instead of the loop
 
Quote:

Originally Posted by fysiks (Post 2181891)
This question doesn't really make much sense. I think we have an XY Problem here.

Please explain, in detail, what you are actually trying to do.

I'm making a plugin. This plugin will use the ".ini" save player views. And making a menu to list the player views. Whenever the players to express their views, plugin will be saved to the bottom parts of the file. But I would like to list the latest comments. So I want to instead of the loop. How to do that? THANK YOU!

Backstabnoob 08-10-2014 05:41

Re: Instead of the loop
 
So if you want to list the latest 5 entries, do for ( new i=max-5; i < max; i++) or do a decrementing loop to start from the end?

yl2401 08-10-2014 06:16

Re: Instead of the loop
 
Quote:

Originally Posted by Backstabnoob (Post 2181927)
So if you want to list the latest 5 entries, do for ( new i=max-5; i < max; i++) or do a decrementing loop to start from the end?

THANK YOU! But I want to show the latest one to the first item in menu, show the second one to the second item in menu, and so on. So how to do a decrementing loop?

Backstabnoob 08-10-2014 07:04

Re: Instead of the loop
 
Exactly the way you first posted.

for (new i=max; i > max-5; i--)

Depending on how the 'lines' are indexed, you might have to do new i=max-1.

for () loops are simple, you just need to learn how they work. They consist of three parameters: starting value, condition that dictates when the loop should break and incremental/decremental value.

aron9forever 08-10-2014 07:33

Re: Instead of the loop
 
Quote:

Originally Posted by yl2401 (Post 2181854)
Normal:
PHP Code:

for( new ii<maxi++ ) 

if max = 2, "i" had 1 and 2.

Opposite:
PHP Code:

for( new i=maxi>0i-- ) 

if max = 2, "i" had 0 and 1.

1 and 2, how to make it in the opposite?
THANK YOU!

what you're saying is wrong
for the first code, if max = 2, i will become 0, then it will become 1, then the loop will stop
for the second code, or opposite as you call it, first i value will be 2(where max=2), second value will be 1 and then it will stop

if you're using arrays beware that usually cell alocation starts from pos 0 and ends in pos max-1, so the last character is a string ender(or whatever it's called in english)
so you might wanna go for
PHP Code:

for(new i=max-1;i>=0;i--) 



All times are GMT -4. The time now is 13:12.

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