Forum

> > CS2D > Scripts > How to stop 'for'
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to stop 'for'

8 replies
To the start Previous 1 Next To the start

old How to stop 'for'

Mami Tomoe
User Off Offline

Quote
Hi, I have a !moneyall command in my script but my problem is that I'm trying to send a message while giving money to all 32 players but it causes the message to show a few times (5 players = 5 messages)

More >


I tried many things like creating functions and doing other random stuff which didn't had much effect regarding the script.

Please

old Re: How to stop 'for'

Mami Tomoe
User Off Offline

Quote
Can you show me where should I place it? Because I've tried placing break but Notepad++ showed it closed an if statement

old Re: How to stop 'for'

VADemon
User Off Offline

Quote
@user Mami Tomoe: You don't need break/return in this case, you have to rewrite/rethink the whole logic of the for-loop and the if-statements.

The short answer is to move the messages outside the for-loop, because lines 7-26 are executed for EVERY EXISTING PLAYER and not just once when the command is parsed.
edited 1×, last 04.04.16 10:41:29 pm

old Re: How to stop 'for'

Rainoth
Moderator Off Offline

Quote
Note that I didn't read your code.

If you want everyone to get a message, use
1
msg("Text to display")
If you want certain players to get a message, use
1
msg2(id,"Test to display")
which is basically a private message.

If you replace simple message into msg2, your problem is likely to be solved but it makes no sense to use it if you want to display it to all players unconditionally.

old Re: How to stop 'for'

Mami Tomoe
User Off Offline

Quote
@user Rainoth: Tried that, works the same for msg and msg2

user VADemon has written
@user Mami Tomoe: You don't need break/return in this case, you have to rewrite/rethink the whole logic of the for-loop and the if-statements.

The short answer is to move the messages outside the for-loop, because lines 7-26 are executed for EVERY EXISTING PLAYER and not just once when the command is parsed.

I tried to make a function to do that for me but it called @user Mami Tomoe: error

1
2
3
4
5
6
7
...code...
giveallmsg(id,pl,moneyall)
...code...

function giveallmsg(id,pl,moneyall)
...code...
end

old Re: How to stop 'for'

GeoB99
Moderator Off Offline

Quote
Are you sure that one of the arguments inside the parenthesis of giveallmsg function has a value?

old Re: How to stop 'for'

Rainoth
Moderator Off Offline

Quote
More >


You may want to work on tabbing your code, you use certain things needlessly. I mean, why would you check if a number isn't nil if you check it's value afterwards!? Even if it's nil, you didn't write a message for such a mistake? Also you might want to make up your mind on whether you want to use "rp_msg2" function or "msg2" function.

old Re: How to stop 'for'

Mami Tomoe
User Off Offline

Quote
@user Rainoth: Thanks it worked
More >

Regarding the things you said, the command was experimental so I didn't notice these things and was busy fixing that problem instead.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview