Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


in function, how to handle arguments

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
cd&
Newbie cheater
Reputation: 0

Joined: 08 Apr 2023
Posts: 20

PostPosted: Wed Apr 19, 2023 5:57 am    Post subject: in function, how to handle arguments Reply with quote

function f1(offset,vector)
vector={0, 0, 0}
vector[1]=readFloat(readPointer("game.exe+01016E44")+offset+0x30)
end
vector1={0, 0, 0}
offset1=0x630
f1(offset1,vctor1)
→it doesn't work as I intend

experiment:
function f2(offset,vector)
vector={0, 0, 0}
vector[1]=readFloat(readPointer("game.exe+01016E44")+offset+0x30)
print(vector[1])
print(vector1[1])
end
vector1={0, 0, 0}
offset1=0x630
f2(offset1,vector1)

0.086963586509228 (this float is as I intend)
0 (this float is not as I intend)

function f3(offset,vector)
vector[1]=readFloat(readPointer("game.exe+01016E44")+offset+0x30)
end
vector1={0, 0, 0}
offset1=0x630
f1(offset1,vctor1)
→it works as I intend

in function, why must not I do "vector={0, 0, 0}"
Back to top
View user's profile Send private message
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Fri Apr 21, 2023 9:05 am    Post subject: Re: in function, how to handle arguments Reply with quote

cd& wrote:
function f1(offset,vector)
vector={0, 0, 0}
vector[1]=readFloat(readPointer("game.exe+01016E44")+offset+0x30)
end
vector1={0, 0, 0}
offset1=0x630
f1(offset1,vctor1)
→it doesn't work as I intend

experiment:
function f2(offset,vector)
vector={0, 0, 0}
vector[1]=readFloat(readPointer("game.exe+01016E44")+offset+0x30)
print(vector[1])
print(vector1[1])
end
vector1={0, 0, 0}
offset1=0x630
f2(offset1,vector1)

0.086963586509228 (this float is as I intend)
0 (this float is not as I intend)

function f3(offset,vector)
vector[1]=readFloat(readPointer("game.exe+01016E44")+offset+0x30)
end
vector1={0, 0, 0}
offset1=0x630
f1(offset1,vctor1)
→it works as I intend

in function, why must not I do "vector={0, 0, 0}"


because it overrides the variable with new value, to check if argument was given nil, you need to do
Code:
vector = vector or {0, 0, 0}

of course, you doing it on raw vector(no libraries or files to include to have a full vector structure)
Back to top
View user's profile Send private message
cd&
Newbie cheater
Reputation: 0

Joined: 08 Apr 2023
Posts: 20

PostPosted: Sat Apr 22, 2023 9:18 am    Post subject: Reply with quote

ok,thank you.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites