Jump to content

Failed to Call Objects from the same Resource | HELPPP


KyonaxDEV

Recommended Posts

Hello dear community.

I'm doing a Error Tooltip Resource, I created an Error Client File for all the Errors from my Main Register Resource, and I tried to call that resource by Functions on the same resource, How can I call a Function from the same resource and get The Object File that I want?...

This is my code - Error File (InitTooltipMessage.lua)

---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---
---|                                                                               |---
---|         Script by "Kyonax - Pilar Perfeccionista" Synchronous member          |---
---|       Github: https://github.com/Kyonax • G-Mail: [email protected]       |---
---|                     Code Script from Montgomery Country RP                    |---
---|                            Resource-Script: [init]                            |---
---|                       Name-Script: [InitTooltipMessage]                       |---
---|           Function-Script: Save all the posible Script Errors                 |---
---|                                                                               |---
---|                            DEV-DATE: 31/08/2020                               |---
---|                               Server Script                                   |---
---|                                number: 001                                    |---
---|                                MIT License                                    |---
---|                                                                               |---
---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---
local tooltip = { 
    error = { 
        notDataDigit = {
            name = 'notDataDigit',
            syntax = 'NULL LABEL',
            message = 'El campo actual debe ser completado',
            description = 'El campo en donde te encuentras, es un campo de entrada, es decir necesitas ingresar información para poder continuar.',
            type = 'ERROR',
            number = '1'
        }, 
        notFoundAccount={ 
            name = 'notFoundAccount',
            syntax = 'NULL QUERY LOGIN',
            message = 'No se ha podido encontrar la cuenta en la Base de Datos.', 
            description='Se ha recibido valor NULL al realizar la búsqueda Query del Usuario en la Base de Datos, es decir que el valor Buscado no existe en la Base de Datos.',
            type = 'ERROR',
            number = '2'
        },
        notEqual = {
            name = 'notEqual',
            syntax = 'NOT EQUAL LABEL',
            message = 'Los datos ingresados no son iguales.',
            description = 'Se ha obtenido un ERROR de similitud a la hora de comparar dos valores que deben ser exactamente iguales.',
            type = 'ERROR',
            number = '3'
        }
        incorrectInformation ={
            name = 'incorrectInformation',
            syntax = 'NOT EQUAL QUERY',
            message = 'La información ingresada es incorrecta.',
            description = 'La comparación de el dato obtenido de la Base de Datos y el Ingresado ha devuelto un ERROR de similitud, es decir los datos ingresados no son iguales a los registrados en la base de datos.',
            type = 'ERROR',
            number = '4'
        },
        notFoundVariables = {
            name = 'notFoundVariables',
            syntax = 'NULL INFORMATION',
            message = 'Las variables esenciales tienen como valor NULL.',
            description = 'Variables necesarias para le ejecución del código son de valor NULL, lo que indica que los valores no han sido digitadas o que han sido corrompidos.',
            type = 'ERROR',
            number = '5'
        },
        existAccount = {
            name = 'existAccount',
            syntax = 'MULTIPLE VALUES QUERY',
            message = 'El usuario digitado no se encuentra disponible.',
            description = 'El nombre de usuario para crear la cuenta ya se encuentra registrado en la Base de Datos, lo que causa un error de multiples valores registrados.',
            type = 'ERROR',
            number = '6'
        },
        existDiscordID = {
            name = 'existDiscordID',
            syntax = 'MULTIPLE VALUES QUERY',
            message = 'La ID de Discord digitada ya se encuentra en uso.',
            description = 'La ID de Discord se encontró en la base de datos, lo que quiere decir que otra cuenta está registrada con esta ID.',
            type = 'ERROR',
            number = '7'
        },
        notValidPassword = {
            name = 'notValidPassword',
            syntax = 'LOW SECURITY ACCOUNT',
            message = 'La contraseña no es segura',
            description = 'Existen algunos requerimientos para acceder al Servidor, uno de ellos es tener una contraseña de más de 6 carácteres.',
            type = 'ERROR',
            number = '8'
        } 
    }
}

local function getError(name)
    return tooltip.error[name]
end

local function getTooltip(name)
    return tooltip.error[name].syntax...' '...tooltip.error[name].message...' '...' ['...tooltip.error[name].type...' #'
    ...tooltip.error[name].number...']' 
end

and I tried to call the getTooltip Function from another File called - RegisterBackend.lua - It's a Server Lua File

local test = exports['[init]']:getTooltip('notFoundAccount').message
local test2 = exports['[init]']:getError('notFoundAccount').type

Both Files are on the same Resource call [Init]

And this is my Meta.xml Code

	<!--ERROR-->
<file src="src/error/InitTooltipMessage.lua" type='client'></file>
	<!--Exported Functions-->
<export function='getError' type='client'></export>
<export function='getTooltip' type='client'></export>

The error that I get when I run the Code is this

spacer.png

What I need to do? to call correctly 

 

Plss I'm Stuck in this

Link to comment
2 hours ago, IIYAMA said:

These brackets are used for hidden folders: [hidden folder]

The resource name is the folder that contains DIRECTLY the meta.xml.

Yeah my bad... But I called the resource like that , I have in that folder the meta.xml, and It's working, only I need is call the functions inside the InitTooltipMessage.lua to the file RegisterBackend.lua

spacer.png

Link to comment
1 hour ago, IIYAMA said:

If that resource name is not allowed, then what is the resource name now?

I don't know if that is the problem, I call all my resources like that, and they work normally, the name of that resource is [init] and I called like that ...the problem is... I only want to know how to call a function from a file to another in the same resource.

T4fQ7B8.png

Link to comment

To talk about the original question... The error is solvable easily

 

Look, you've put "local" at the start of the line when you define you function

local function getTooltip(name)

If you add a "local" to a variable (wich can be a function, a string, an integer...) then you won't be able to access it directly from another file

I guess you know what to do now, have a nice day.

Link to comment
12 minutes ago, Gordon_G said:

To talk about the original question... The error is solvable easily

 

Look, you've put "local" at the start of the line when you define you function


local function getTooltip(name)

If you add a "local" to a variable (wich can be a function, a string, an integer...) then you won't be able to access it directly from another file

I guess you know what to do now, have a nice day.

Ok, I did this but the call of the function still return nil

[14:47:42] ERROR: [init]\login\LoginBackend.lua 27: attempt to call global 'getError' (a nil value)

 

---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---
---|                                                                               |---
---|         Script by "Kyonax - Pilar Perfeccionista" Synchronous member          |---
---|       Github: https://github.com/Kyonax • G-Mail: [email protected]       |---
---|                     code script from Montgomery Country RP                    |---
---|                            Resource-Script: [init]                            |---
---|                          Name-Script: [LoginBackend]                          |---
---|      Function-Script: Try to acces to an Account by the parameters gived      |---
---|                        by the Browser GUI using an Event                      |---
---|                                                                               |---
---|                            DEV-DATE: 21/06/2020                               |---
---|                               Server Script                                   |---
---|                                number: 002                                    |---
---|                                MIT License                                    |---
---|                                                                               |---
---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---•---
--- Server Variables
event = {add = addEventHandler, load = addEvent, execute = triggerClientEvent} -- Make simple calls for addEvent and triggerClientEvent by the variable event
--- Variable Error
local error = {
    message = {
        account = "No se ha podido encontrar la cuenta en la Base de Datos [ERROR 3]",
        information = "La información ingresada es incorrecta. Inténtelo nuevamente [ERROR 4]"
    },
    type = "ERROR"
} -- Make simple String calls for errors (account, information) by the variable error
local test = getError('notFoundAccount').message
local test2 = getError('notFoundAccount').type
--- Functions
function loginAttempt(player, user, password)
    local account = getAccount(user) -- Check on the Database the User
    if not account then -- If the account doesn't exist        
        event.execute(player, 'login-tooltip-browser:show', player,
                      test, test2) -- Trigger an Event that shows the error.account on the Browser
    else
        local hashed_password = getAccountData(account, 'hashed_password') -- Get the encrypt password from the Account
        passwordVerify(password, hashed_password, function(areEqual)
            if not areEqual then -- If the Password is incorrect
                event.execute(player, 'login-tooltip-browser:show', player,
                              error.message.information, error.type) -- Trigger an Event that shows the error.information on the Browser
            else
                if logIn(player, account, hashed_password) then
                    spawnPlayer(player, 1280, 250, 20)
                    fadeCamera(player, true)
                    setCameraTarget(player, player)
                    for i = 1, 16 do
                        outputChatBox(' ', player)
                    end
                    return event.execute(player, 'login-browser:remove', player) -- Trigger an Event that Removes the Browser GUI
                end -- If the User login succesfully then spawn and set the camera to the Player
            end
        end) -- Verify if the Password is equal to the Account Password
    end -- Verify if the account exists
end -- This function try to Login into the account if it can't send an Error
--- Events Created
event.load("login-backend:execute", true)
event.add("login-backend:execute", root,
          function(user, password) loginAttempt(client, user, password) end) -- An Event that try to acces to the Account by the User and Password
--- MTA Events          
event.add("onPlayerLogout", root,
          function() event.execute(source, "login-browser:show", source) end) -- When the Player Logout the Session Open the Browser GUI

 

Link to comment
  • Moderators
31 minutes ago, KyonaxDEV said:

Ok, I did this but the call of the function still return nil

Export functions must be a global, so that whole concept will probably not work.

 

Here was a similar quest asked, with 2 possible solutions when you want to re-use the same function name.

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...