Raised This Month: $ Target: $400
 0% 

[Solved] Function argument gets overwritten...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mptijsma
Member
Join Date: Mar 2006
Old 04-29-2006 , 06:01   [Solved] Function argument gets overwritten...
Reply With Quote #1

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!
mptijsma is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 04-29-2006 , 06:23  
Reply With Quote #2

Text is a global array which passed to the function by reference so inside function ImportantBlaat and Text is the same array.
VEN is offline
mptijsma
Member
Join Date: Mar 2006
Old 04-29-2006 , 06:26  
Reply With Quote #3

Thank you for figuring out ^^.
mptijsma is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-29-2006 , 06:30  
Reply With Quote #4

Next time use copy() instead of format() for your situtation ;)
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
mptijsma
Member
Join Date: Mar 2006
Old 04-29-2006 , 06:32  
Reply With Quote #5

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).
mptijsma is offline
Reply


Thread Tools
Display Modes

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 05:03.


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