Testing for Too Many Event Names (causes lag)

Description: Archive discussion
============================
Original description:
Official subforum for LunaLua - an extension framework for SMBX Engine Version 1.3 (which a core of SMBX 2.0). Share your creations that require the use of LunaLUA. You may also share info/tutorials on how to use LunaLUA.

Sambo M
Topic author, Count
Count
Avatar
Sambo M
Topic author, Count
Count
Age: 25
Reputation: 15
Posts: 264
Joined: 27 Jun 2014

Post #1by Sambo » 17 May 2015, 4:48

on the onEvent function, I have it testing for too many event names, and it lags. However, I can't just remove them because I need them for my custom HUD to work. Is there a way to test for all of the events without doing it every time an event is called? All of the events I test for start with "dc-trig-" followed by a number. In my normal levels it is testing for 5 of them and still runs smoothly, but in some, I'm testing for 10, and it causes lag. So, what I basically want to do is be able to parse only the first few letters of an event's name and not test all of them unless the "dc-trig-" part is present.
Image
Current Project:
Image

Kevsoft M
Angry developer
Angry developer
Avatar
Kevsoft M
Angry developer
Angry developer
Age: 24
Reputation: 93
Posts: 379
Joined: 26 Apr 2014
Location: Austria
Website

Post #2by Kevsoft » 17 May 2015, 8:23

The probably easiest way is:

Code: Select all

if(myEventName:find("dc-trig-"))then


Btw, next release comes with luajit. Luajit should run code x2 to x100 faster than the normal lua.
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.start() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.end() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬

Sambo M
Topic author, Count
Count
Avatar
Sambo M
Topic author, Count
Count
Age: 25
Reputation: 15
Posts: 264
Joined: 27 Jun 2014

Post #3by Sambo » 20 May 2015, 3:32

Code: Select all

function onEvent(eventName)
   if(eventName:find("dc-trig-"))then
      if split_route == false then
         if eventName == "dc-trig-1" then
            ...
         end
      end
   end
end

This doesn't seem to work; the events won't trigger anything in Lua with the find() function there.
EDIT:
You don't need to help me fix that. It turns out that the lag was actually caused by a bad onLoop function routine that was placing 2 sprites on the screen per frame.
Image
Current Project:
Image


Return to “LunaLua - Extension Framework”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest