Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function isClass #4640

Merged
merged 1 commit into from
Apr 2, 2024
Merged

New function isClass #4640

merged 1 commit into from
Apr 2, 2024

Conversation

MillhioreBT
Copy link
Contributor

Pull Request Prelude

Changes Proposed

This new method would help us know if the datatype belongs to a specific class.
Although we can do the raw comparison using the getmetatable function, it seems more intuitive to have this method with the name isClass

Cases in which it can be useful:

  • There are some cases in which a method returns a cylinder and this cylinder can be a player, a container or a tile, so if you want to know if it is a tile, you cannot execute the isTile method, because if it is a player or a container this method does not exist, but in the opposite case if you want to know if the cylinder is a player you can use isPlayer, but if the cylinder happens to be a tile there will be an error because isPlayer does not exist
Example
local event = Event()

function event.onMoveItem(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
	if isClass(toCylinder, Tile) then
		player:sendTextMessage(MESSAGE_INFO_DESCR, "To Tile.")
	elseif isClass(toCylinder, Player) then
		player:sendTextMessage(MESSAGE_INFO_DESCR, "To Player.")
	elseif isClass(toCylinder, Container) then
		player:sendTextMessage(MESSAGE_INFO_DESCR, "To Container.")
	end

	return RETURNVALUE_NOERROR
end

event:register()

The other option would be to add all the methods corresponding to all the classes:

  • isTile, isPlayer, isCreature, isMonster, isItem, isContainer, isTeleport, isNpc
    and their respective get
  • getTile, getPlayer, getCreature, getMonster, getItem, getContainer, getTeleport, getNpc

Issues addressed: Nothing!

@MillhioreBT MillhioreBT added the priority: low Issues with this label won’t have the immediate focus label Apr 1, 2024
@MillhioreBT MillhioreBT merged commit 6ad39c4 into otland:master Apr 2, 2024
4 checks passed
@MillhioreBT MillhioreBT deleted the is_class branch April 2, 2024 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low Issues with this label won’t have the immediate focus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants