Giter Site home page Giter Site logo

Comments (6)

itsxScrubz avatar itsxScrubz commented on August 29, 2024

It's because the syntax is Callbacks:TriggerCallback(callback_name, function, data_being_sent)

from callbacks.

itsxScrubz avatar itsxScrubz commented on August 29, 2024

Since you flipped the data being returned with the data you're trying to send, the query isn't finding anything and therefor never triggering the callback function.

from callbacks.

TheDevster avatar TheDevster commented on August 29, 2024

So a modification, such as below should work right? Where callbackname is 'get_store_cost', function is where callback data will be stored (yes?), and the last parameters being the data from client that is being sent to server?

store is a table that gets sent as the data from client to the server.

 local storeprice
  Callbacks:TriggerCallback('get_store_cost', function(data) 
    print(data)
    storeprice = data
  end, store)

and my server side still good?

  Callbacks:RegisterCallback('get_store_cost', function(data, source, cb)
    print("Made it here")
    print("SOURCE", source)
    MySQL.Async.fetchAll('select price, store_bank from stores WHERE store_id=@id_store', 
    {
      ['id_store'] = source.id
    }, function(results)
      if #results > 0 then 
        total_price = round_monies(results[1].price + results[1].store_bank)
        cb(total_price)
      end
    end)
  end)

I assume with registering it's the same order of functions right?

from callbacks.

itsxScrubz avatar itsxScrubz commented on August 29, 2024

['id_store'] = source.id

Since your sending data thru the callback, this should be ['id_store'] = data
function(data_sent_from_client, source, callback_function)

from callbacks.

TheDevster avatar TheDevster commented on August 29, 2024

Nice! Ok I got it to work with your help! I really appreciate that. I do notice that if I change the code and restart my resource, I also have to restart the callback resource or I end up with errors like this:
[script:callbacks] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:853: bad argument #1 to 'unpack' (table expected, got nil)

Hopefully I can gain some of my brain cells back now that I am heading in the correct direction..

from callbacks.

itsxScrubz avatar itsxScrubz commented on August 29, 2024

It's due to how the resource is written. When you restart the callbacks, the table that holds them via: [ Callbacks = exports['callbacks']:FetchCallbacks() ] no longer exists. All you would have to do is just reassign the variable with the export again. These callbacks were in my framework, and when you restart a resource it automatically refreshes that component. Since they are standalone, this isn't the case!

But glad to be of help.

from callbacks.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.