Raised This Month: $51 Target: $400
 12% 

[HELP] Switching two variables


Post New Thread Reply   
 
Thread Tools Display Modes
AoD90
Senior Member
Join Date: Jul 2008
Location: Ugljevik/RS/BIH
Old 12-27-2008 , 14:51   Re: [HELP] Switching two variables
Reply With Quote #11

This all works. Thanks.

Is there way to switch two words too?

Last edited by AoD90; 12-28-2008 at 03:17.
AoD90 is offline
Send a message via MSN to AoD90
IneedHelp
Veteran Member
Join Date: Mar 2007
Location: Argentina
Old 12-27-2008 , 15:24   Re: [HELP] Switching two variables
Reply With Quote #12

Hey Daniel what's that operator ^= ? I never see it O.o
__________________
IneedHelp is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 12-27-2008 , 15:36   Re: [HELP] Switching two variables
Reply With Quote #13

Assignment XOR (exclusive disjunction).

http://en.wikipedia.org/wiki/XOR
http://en.wikipedia.org/wiki/XOR_swap_algorithm
__________________
No support via PM.

Last edited by Lee; 12-27-2008 at 15:48.
Lee is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 12-27-2008 , 19:37   Re: [HELP] Switching two variables
Reply With Quote #14

Quote:
Originally Posted by Lee View Post
That's simple stuff - I understood nearly 1% of it easily!
__________________
O o
/¯________________________
| IMMA FIRIN' MAH LAZOR!!!
\_¯¯¯
Dores is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 12-27-2008 , 22:09   Re: [HELP] Switching two variables
Reply With Quote #15

Quote:
Originally Posted by Dores View Post
That's simple stuff - I understood nearly 1% of it easily!
XOR = Toggle each bit if the correspondent bit of both the operands are different.

Example (number represented as bits)

111 XOR 111 = 000 (all bits equal)
000 XOR 111 = 111 (all bits different)
001 XOR 000 = 001 (only last bit different)
__________________

Community / No support through PM
danielkza is offline
AoD90
Senior Member
Join Date: Jul 2008
Location: Ugljevik/RS/BIH
Old 12-28-2008 , 07:16   Re: [HELP] Switching two variables
Reply With Quote #16

Quote:
Originally Posted by AoD90 View Post
This all works. Thanks.

Is there a way to switch two words too?
AoD90 is offline
Send a message via MSN to AoD90
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 12-28-2008 , 07:29   Re: [HELP] Switching two variables
Reply With Quote #17

[OT]@danielkza: So if the 2 bits are different, the result will be the bit that is less close to 000?

i.e:
010 XOR 011 = 011? // 011 > 010? Or it doesn't work like that with bits?
100 XOR 011 = 100? // 100 > 011?[/OT]


@AoD90:

Try this:
PHP Code:
// lenz = number of characters to swap.
stock swap_wordswordA[], wordB[], lenz )
{
    new 
temp250 ]; // 250 will be the maximum number of character the wordA can contain. Edit this to your liking.
//    You must make sure that lenz is NOT bigger than temp's size.
    
    
formattemplenz 1"%s"wordA );
    
formatwordAlenz 1"%s"wordB );
    
formatwordBlenz 1"%s"temp );
    
    return 
1;

Example of usage:
PHP Code:
#include <amxmodx>

// lenz = number of characters to swap.
stock swap_wordswordA[], wordB[], lenz )
{
    new 
temp250 ]; // 250 will be the maximum number of character the wordA can contain. Edit this to your liking.
//    You must make sure that lenz is NOT bigger than temp's size.
    
    
formattemplenz 1"%s"wordA );
    
formatwordAlenz 1"%s"wordB );
    
formatwordBlenz 1"%s"temp );
    
    return 
1;
}

public 
plugin_init()
{
    
register_clcmd"say /swap""myFunction" );
}

public 
myFunctionid )
{
    new 
HelloWorld[] = "HelloWorld!";
    new 
WorldHello[] = "WorldHello!";
    
    
swap_wordsHelloWorldWorldHello11 );
    
client_printidprint_chat"HelloWorld: %s    WorldHello:    %s"HelloWorldWorldHello );

__________________
O o
/¯________________________
| IMMA FIRIN' MAH LAZOR!!!
\_¯¯¯

Last edited by Dores; 12-28-2008 at 08:05.
Dores is offline
AoD90
Senior Member
Join Date: Jul 2008
Location: Ugljevik/RS/BIH
Old 12-28-2008 , 07:42   Re: [HELP] Switching two variables
Reply With Quote #18

I got some error:

Error:Must be a constant expression; assumed zero on line 98
Error:Invalid array size (negative or zero) on line 100
Error:Undefined symbol "temp" on line 100
AoD90 is offline
Send a message via MSN to AoD90
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 12-28-2008 , 08:06   Re: [HELP] Switching two variables
Reply With Quote #19

Fixed last post.
Test and tell me the results.
__________________
O o
/¯________________________
| IMMA FIRIN' MAH LAZOR!!!
\_¯¯¯
Dores is offline
AoD90
Senior Member
Join Date: Jul 2008
Location: Ugljevik/RS/BIH
Old 12-28-2008 , 10:28   Re: [HELP] Switching two variables
Reply With Quote #20

Very nice. Thanks a lot
AoD90 is offline
Send a message via MSN to AoD90
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:35.


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