AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved] Function argument gets overwritten... (https://forums.alliedmods.net/showthread.php?t=27782)

mptijsma 04-29-2006 06:01

[Solved] Function argument gets overwritten...
 
I'm having a problem with a function argument getting overwritten by another value.

The problem:
ImportantBlaat[] becomes the content of Text[];

When I call the function, ImportantBlaat[] is equal to Text[].

Maybe when Text[] is changed with read_file(), ImportantBlaat[] will be changed again so it becomes equal to Text[] again?

Actually, this is what's happening.

The test plugin:
Code:
new Text[1024],Size,File[]="blaat.txt"; public plugin_init() {     format(Text,sizeof(Text),"%s","This is REALLY important!");     function(Text); } public function(ImportantBlaat[]) {         // Debug: ImportantBlaat[] = "This is REALLY important!"        read_file(File,0,Text,sizeof(Text),Size);     // Debug: ImportantBlaat[] = "blaat"     server_print(ImportantBlaat); }

Contents of blaat.txt:
Code:

blaat
Output:
Code:

blaat
Desired output:
Code:

This is REALLY important!

VEN 04-29-2006 06:23

Text is a global array which passed to the function by reference so inside function ImportantBlaat and Text is the same array.

mptijsma 04-29-2006 06:26

Thank you for figuring out ^^.

v3x 04-29-2006 06:30

Next time use copy() instead of format() for your situtation ;)

mptijsma 04-29-2006 06:32

Quote:

Originally Posted by v3x
Next time use copy() instead of format() for your situtation ;)

Since I didn't know where the error was exactly (I totally forgot that all arrays in Pawn are passed by reference), I included the format() I use in the 'real' code (different usage though).


All times are GMT -4. The time now is 05:03.

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