• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua ~= 1/== 1

Wavoz

Oldschooler
Joined
Jul 10, 2011
Messages
1,009
Reaction score
81
Hello
I have been surfing on lua.org but finding answers to your questions is difficult when you are not native English speaker, so i need to understand few things. I pretty much understand what some functions do and i know how to fix some problems and i can modify scripts for my own need but i can't make script from scratch. I just realized i've been using this same style for a while and i don't quite understand it.

Ive made this script: (Summons Assassin if you use sleeping body on a bed)
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local storageValue = 26000 
	if(getPlayerStorageValue(cid, storageValue) ~= 1) then
	doSummonCreature("Assassin", getClosestFreeTile(cid,  getThingPos(cid)))
	doSendMagicEffect(toPosition,12)
     doPlayerSendTextMessage(cid, 22, 'You have woken the Assassin!')
     setPlayerStorageValue(cid, 26000, 1)
 	return true
end
	if(getPlayerStorageValue(cid, storageValue) == 1) then
     doPlayerSendTextMessage(cid, 22, 'Assassin is in a deep sleep, do not push your luck again!')
		end
		return TRUE
	end

What does ~= 1 means? I understand that ==1is like "yes", so ~=1 is like no? Can i use ==0 as no? Are these numbers like conditions because sometimes they go over 1, 2, 3?

I would appreciate if someone could explain me.
 
== means 'equal to'

~= means 'if not' or 'different than'

Example:

1+1 == 2

1+1 is equal to 2
1+1 = 2

1+1 == 2 returns true.


Example 2:

1+2 ~= 5

1+3 ~= 5(=5) ? No, that's wrong. And that's how it works :), now it returns true

If the answer is wrong or different than it's supposed to be ( in this case, 1+3 = 5 is actually 1+3 = 4, so it returns true )

1+1~= 2 will return false
 
Last edited:
Explaining your script

Code:
if(getPlayerStorageValue(cid, storageValue) ~= 1) then

If the storage value is different (~=) than 1, then the code will execute this part

Code:
doSummonCreature("Assassin", getClosestFreeTile(cid,  getThingPos(cid)))
doSendMagicEffect(toPosition,12)
doPlayerSendTextMessage(cid, 22, 'You have woken the Assassin!')
setPlayerStorageValue(cid, 26000, 1)

Else if the storage value is equal (==) to 1, the script will execute the message
Code:
doPlayerSendTextMessage(cid, 22, 'Assassin is in a deep sleep, do not push your luck again!')

It's easy bro!
Hope u get it ;]
 
Ye i've always known when to use it but i didn't understand why is it like that. I get it now, i would like to thank both of you!
 

Similar threads

Back
Top Bottom