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 


Can I Get A Hand With These 2 Functions?

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

Joined: 04 Jan 2018
Posts: 16
Location: Anime Heaven

PostPosted: Mon Jun 10, 2019 4:13 pm    Post subject: Can I Get A Hand With These 2 Functions? Reply with quote

Hey so im trying to do something and i dont get how i can use these 2 functions? can someone help me?

first one is function tonumber(string)

second one is function ansiToUtf8(String) : string

thanks in advance.

_________________
Im A No Life
Back to top
View user's profile Send private message AIM Address
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Mon Jun 10, 2019 11:10 pm    Post subject: Reply with quote

Example:

Code:
a = 2
b = 3
print(a+b)

-- result = 5.0
-- because a and b is numbers

a = 2
b = '3'
print('a is '..type(a))
print('b is '..type(b))

-- result
-- a is number
-- b is string

print(a+b)

-- Error:[string "a = 2..."]:10: attempt to perform arithmetic on a string value (global 'b')
-- because try to make math addtion a (number) + b (string)

-- convert b value from string to number
b=tonumber(b)

-- test
print(a+b)
-- result = 5



function ansiToUtf8(String) : string
Converts a string in Ansi encoding to UTF8

ANSI stands for American National Standards Institute.
The ANSI character set includes the standard ASCII character set (values 0 to 127),
plus an extended character set (values 128 to 255).
The ANSI character set is used by Windows end refers to the codepage 1252 known as "Latin 1 Windows"

ANSI Table : http://ascii-table.com/ansi-codes.php
UTF8 Table : https://www.utf8-chartable.de/unicode-utf8-table.pl

Code:
str = 'ƒ ‰ ®' -- is ANSI string text
print(ansiToUtf8(str))
-- result = 'Æ’ ‰ ®'  -- is UTF8 characters



Addition: UTF8 Characters

Example to print out: ʸ√x + ʸ√2 - x²

Code:
print(utf8.char(0x02B8)..utf8.char(0x221A)..'x'..'+'..utf8.char(0x02B8)..utf8.char(0x221A)..'2'..'-'..'x'..utf8.char(0x00B2))


EDIT:
I guess you are play FF game series

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 959

PostPosted: Tue Jun 11, 2019 2:57 am    Post subject: Reply with quote

What version the lua you are using?
Lua do implicit conversion in some case
Code:

-- lua @ ce 6.6
local a,b = 1,"2.5"
print(a+b) // 3.5 - number
print(b..a) // 2.51 - string

_________________
- Retarded.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Tue Jun 11, 2019 4:46 am    Post subject: Reply with quote

Yes, Panranven. I think from my sample:

Code:
a = 2
b = '3'
print(a+b)


should be = 5 because Lua will automatically translate this b = '3' as a number, but the error appears on my CE 6.8.3 (Lua 5.3) as shown above. I tried again on my Lua 5.3 for window console, the code 2 + '3' give result 5.0.

I have tested again CE 6.8.3 and test the same code (without any other line code) and the result is 5.0.

Back to the topic which asked for, here another reference:

Code:
> = 100 == "100"
false
> = 100 ~= "hello"
true
> = 100 ~= {}
true
> = 100 == tonumber("100")
true
> = 100 <= "100"
stdin:1: attempt to compare number with string
stack traceback:
        stdin:1: in main chunk
        [C]: ?

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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 Lua Scripting 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