Raised This Month: $ Target: $400
 0% 

[HELP] Switching two variables


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 12-26-2008 , 18:30   Re: [HELP] Switching two variables
Reply With Quote #1

Quote:
Originally Posted by anakin_cstrike View Post
Well...
PHP Code:
new 57;
new 
aux;
 
aux y;
aux;
x
And that isn't even right.
[ --<-@ ] Black Rose is offline
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 12-27-2008 , 05:39   Re: [HELP] Switching two variables
Reply With Quote #2

Yeah...i saw now.
__________________

anakin_cstrike is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-27-2008 , 12:04   Re: [HELP] Switching two variables
Reply With Quote #3

SnoW, yes it can:
Code:
stock replaceint(&a, &b) {     new temp = a;     a = b;     b = temp; }

daniel, won't that only work because those are 2 numbers that are able to do that?
What about 3 and 7?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 12-27-2008 , 12:49   Re: [HELP] Switching two variables
Reply With Quote #4

Quote:
Originally Posted by Exolent[jNr] View Post
SnoW, yes it can: Code:
stock replaceint(&a, &b) { new temp = a; a = b; b = temp; }


daniel, won't that only work because those are 2 numbers that are able to do that?
What about 3 and 7?
It works for everything
Code:
new a = 3, b = 7 //a = 011b, b = 111b)

a ^= b // 011b ^ 111b = 100b
b ^= a // 111b ^ 100b = 011b
a ^= b // 100b ^ 011b = 111b

// a == 7, b == 3 //a = 111b, b = 011b)
__________________

Community / No support through PM
danielkza is offline
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 #5

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
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 #6

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 #7

[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
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 23:10.


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