How do I get a variable from a event able to be compared?

Started by Ziplogcom, Dec 21, 2021, 09:10 PM

Previous topic - Next topic

Ziplogcom

I'm trying to pull a variable from a event, and it doesn't want to compare the variable to the string. I already know it's a string
(data from the BPeripherals Magcard) but I can't get the computer to see it my way.
😳

aeiou
--‐----------------------
I make kinda... kinda bad programs.

Lupus590

Have you tried printing what you are trying to compare?

It's possible that you are comparing the event wrong, the first value is always the event type even when you passed an event filter.

local eventType, side, uuid, data = os.pullEvent("mag_swipe")

print(eventType) -- "mag_swipe"
print(side)      -- "left"/"right"/etc
print(uuid)      -- something like "73f6077e-c4fe-4703-bd58-690eaac263c4"
print(data)      -- the string you probably want

It might also be case sensitivity, "example" and "Example" are not the same to Lua because it sees "e" and "E" as different. If you want it to see them as the same then you need to use string.upper() on both of them or string.lower().

local str1 = "Example"
local str2 = "example"

print(str1 == str2)
print(str1:upper() == string.upper(str2)) -- both of the function calls to upper here are equivalent, one uses the string meta table the other uses the string API
print(str1:upper()) -- just so that we can see what upper does
print(str1:lower() == string.lower(str2)) -- both lowers are the same too
print(str1:lower()) -- likewise to see what it does

If none of this has helped then posting your code will help me help you. I'm not familiar with the peripheral so seeing what you are doing might help me to help you. Although I have found its wiki which has helped me write this.