Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Fri Feb 24, 2017 10:29 am

Take a look at NPC.getIntersecting()

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Fri Feb 24, 2017 11:12 am

PixelPest wrote:Take a look at NPC.getIntersecting()
Either that, or using the colliders library, which allows you to call colliders.collideNPC, which can detect against all NPCs of a given ID.

ssumday
Swooper
Swooper
Posts: 78
Joined: Wed May 14, 2014 1:18 pm
Flair: Nope

Re: Need help with lua? - LunaLua General Help

Postby ssumday » Fri Feb 24, 2017 9:43 pm

Thank you very much! Colliders.lua is exactly what I needed.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Mon Feb 27, 2017 10:35 pm

Is there a way to access the profiler lag data with lua (the stuff that shows up when you push F3)?

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Tue Feb 28, 2017 2:50 am

Quantumenace wrote:Is there a way to access the profiler lag data with lua (the stuff that shows up when you push F3)?
I don't believe it is, not directly at least.

However, all of that is itself drawn in Lua, so you can get the raw data yourself and interpret it. The code for it can be found at LuaScriptsLib>core>profiler.lua.

It's fairly complex to get your head around, but should be possible to re-interpret.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Tue Feb 28, 2017 3:36 am

Thanks. Ok, yeah, it is kind of out there. I just wanted to know if there was a better way to measure lag.

Currently I have it set up to measure the wait time after onDrawEnd and before the next onTick. If it starts getting low I throttle the number of particles produced. It actually works pretty well.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Tue Feb 28, 2017 1:32 pm

Quantumenace wrote:Thanks. Ok, yeah, it is kind of out there. I just wanted to know if there was a better way to measure lag.

Currently I have it set up to measure the wait time after onDrawEnd and before the next onTick. If it starts getting low I throttle the number of particles produced. It actually works pretty well.
Ah, dynamic adjustment. Neat. You'd be better off measuring between the same call, though, as that's what the actual framerate would be. The eventu API provides a "deltaTime" value that you could use for this, which gives you the time the last frame took to render.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Tue Feb 28, 2017 3:07 pm

Hoeloe wrote:
Quantumenace wrote:Thanks. Ok, yeah, it is kind of out there. I just wanted to know if there was a better way to measure lag.

Currently I have it set up to measure the wait time after onDrawEnd and before the next onTick. If it starts getting low I throttle the number of particles produced. It actually works pretty well.
Ah, dynamic adjustment. Neat. You'd be better off measuring between the same call, though, as that's what the actual framerate would be. The eventu API provides a "deltaTime" value that you could use for this, which gives you the time the last frame took to render.
Thanks, but deltaTime doesn't start to change until the game has already started lagging and I'm trying to head that off. I should probably measure the time taken between onLoop and onDrawEnd, the wait afterward might get inflated by other processes on low-number core systems as far as I know.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Wed Mar 01, 2017 2:58 am

Quantumenace wrote: Thanks, but deltaTime doesn't start to change until the game has already started lagging and I'm trying to head that off.
It's difficult to detect frame loss before it happens. If all you're doing is changing particle counts, then your best bet is probably to wrap just those particle draw calls in a time test. You can use os.clock() to get the current time, and if you store that before drawing them, then compare it after drawing them, you can get a good idea of just how long your particle rendering takes (and therefore is a useful measure for how much you should decrease it by).

If you want to run across the whole frame, you should start from onInputUpdate and end with onDrawEnd, I think, which should get you a measure for how long your Lua is taking. Compare that to the value in lunatime.toSeconds(1), which will give you an accurate default frame rate without lag (the time in seconds for one tick). Your measured value should be a lot lower than that. If it gets even above half that value, you can start dropping particles.

Angelus
Tweeter
Tweeter
Posts: 132
Joined: Tue Jun 21, 2016 9:38 am

Re: Need help with lua? - LunaLua General Help

Postby Angelus » Wed Mar 01, 2017 10:31 am

What can I do regards camera with LunaLua? Can I increase the camera update speed, so the transition is faster?

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Mar 01, 2017 10:32 am

Angelus wrote:What can I do regards camera with LunaLua? Can I increase the camera update speed, so the transition is faster?
What transition? Can't you just speed up the transition or the camera itself?

Angelus
Tweeter
Tweeter
Posts: 132
Joined: Tue Jun 21, 2016 9:38 am

Re: Need help with lua? - LunaLua General Help

Postby Angelus » Wed Mar 01, 2017 10:34 am

Do you know when we set the camera to move into a previously inaccessible area of a section through an event? It does take a while 'till the camera sets its place. Can't I make it move faster?

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Wed Mar 01, 2017 10:53 am

Like autoscroll? You can increase the speed that way without any code. This class also works to move the camera or lock it in place: http://wohlsoft.ru/pgewiki/Camera_(class)

Angelus
Tweeter
Tweeter
Posts: 132
Joined: Tue Jun 21, 2016 9:38 am

Re: Need help with lua? - LunaLua General Help

Postby Angelus » Wed Mar 01, 2017 11:00 am

No, it's not autoscroll. Let me elaborate it better:

In the event settings, you can set the camera boundaries to move somewhere else if a specific event is activated. Then it will lock into a new area. It can be to the right of the screen (which was not accessible earlier on until you activated the said event), or to any other direction. When you activate it, the camera moves its boundaries to a new area defined at the event settings. Then, we have a transition, where the camera slowly moves to the right, or to the left, etc., 'till it stops so you can regain control over the player. I would like to increase the speed of this short transition of the camera boundaries movement when it is setting to a new place.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Wed Mar 01, 2017 11:07 am

Hoeloe wrote: you can get a good idea of just how long your particle rendering takes (and therefore is a useful measure for how much you should decrease it by).
I'm trying to account for all sources of lag, including Spike Tops and other gameplay stuff. The particles are the only thing I can really scale to compensate.
Hoeloe wrote:If you want to run across the whole frame, you should start from onInputUpdate and end with onDrawEnd, I think, which should get you a measure for how long your Lua is taking. Compare that to the value in lunatime.toSeconds(1), which will give you an accurate default frame rate without lag (the time in seconds for one tick). Your measured value should be a lot lower than that. If it gets even above half that value, you can start dropping particles.
Yeah, this is what I'm doing. I tested, and onLoop executes before onInputUpdate. Didn't know about the lunatime one though, thanks.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Fri Mar 03, 2017 3:53 am

Angelus wrote:No, it's not autoscroll. Let me elaborate it better:

In the event settings, you can set the camera boundaries to move somewhere else if a specific event is activated. Then it will lock into a new area. It can be to the right of the screen (which was not accessible earlier on until you activated the said event), or to any other direction. When you activate it, the camera moves its boundaries to a new area defined at the event settings. Then, we have a transition, where the camera slowly moves to the right, or to the left, etc., 'till it stops so you can regain control over the player. I would like to increase the speed of this short transition of the camera boundaries movement when it is setting to a new place.
The autoscroll API has a autoscroll.scrollToBox(gX1, gY1, gX2, gY2, speed, section) function. It looks like you can put the new section bounds in there and it will expand at the specified speed without disabling player controls at all. Try a speed of 8, faster than running speed. It's possible to set the bounds instantly but that can end up jarring.

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Sun Mar 05, 2017 10:09 pm

What to do?
Image

This is the code by the way:

Code: Select all

function OnLoad()
	 Level.loadPlayerHitBoxes(4, 1, "toad-1.ini")
	 Level.loadPlayerHitBoxes(4, 2, "toad-2.ini")
	 Level.loadPlayerHitBoxes(4, 3, "toad-3.ini")
	 Level.loadPlayerHitBoxes(4, 4, "toad-4.ini")
	 Level.loadPlayerHitBoxes(4, 5, "toad-5.ini")
	 Level.loadPlayerHitBoxes(4, 6, "toad-6.ini")
     Level.loadPlayerHitBoxes(4, 7, "toad-7.ini")
end

function onTick()
	if Player.jumpKeyPressing == true then
	if player.character == 4 then
	if Player.altRunKeyPressing == true then
	if Player.rightKeyPressing == true then
	player.speedX = 5;
	Audio.playSFX("dash.wav")
	elseif Player.altRunKeyPressing == true then
	if Player.leftKeyPressing == true then
	player.speedX = -5;
	Audio.playSFX("dash.wav")
	elseif Player.altRunKeyPressing == true then
	if Player.downKeyPressing == true then
	player.speedY = 7;
	Auido.playSFX("dash.wav")
	end
	end
end

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sun Mar 05, 2017 10:23 pm

That error message means that you're missing an end, however that's only the start of your problems. The code itself is a grand mess tbh. It's inefficient and it appears that you don't understand even the basics of conditional statements. I'd recommend reading an online tutorial of Lua so that you can learn how to fix it yourself. Also remember to use onStart() instead of onLoad(). This is basically what the code in onStart() should look like, but please do yourself a favour and learn the basics. I'm not even going to attempt to fix the rest since it's hard to tell what you want to accomplish. Remember not to test for true, just do if var then instead of if var == true then. Also, Player needs a lower case p. Player is the class while player is the object. In addition to that, remember that you can group multiple items into one conditional statement with and, such as if var1 == 1 and var3 == 8 and var2 == 10 then, and for each condition you make it has to have an end to close it.
Spoiler: show

Code: Select all

function onStart()
   for i = 1, 7 do
      Level.loadPlayerHitboxes(4, i, "toad-"..tostring(i)..".ini");
   end
end

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Mon Mar 06, 2017 9:57 pm

Okay, so i re-wrote the entire code, but i have two questions:
the first question is, is this written correctly?:

Code: Select all

local dashsound = Audio.playSFX("dash.wav")
local TableOfBoostDash = {a = player.jumpKeyPressing,  b = player.altRunKeyPressing, c = player.rightKeyPressing, d = player.leftKeyPressing, e = player.downKeyPressing}
local TableOfBoostDirection = {sa = player.speedX = -5, sb = player.speedX = 5, sc = player.speedY = 5}
local a = player.jumpKeyPressing
local b = player.altRunKeyPressing
local c = player.rightKeyPressing
local d = player.leftKeyPressing
local e = player.downKeyPressing
local sa = player.speedX = -5
local sb = player.speedX = 5
local sc = player.speedY = 5
local haveBoosted = false;
local haveBoostedDown = false;

function onLoop()
	if player:mem(0x146, FIELD_WORD) == 2 then
		HaveBoosted = false;
		HaveBoostedDown = false;
	end
end

function onStart()
   for i = 1, 7 do
      Level.loadPlayerHitboxes(4, i, "toad-"..tostring(i)..".ini");
	end
end

function OnStart()
	if TableOfBoostDash[a] then
	if TableOfBoostDash[b] then
	if TableOfBoostDash[c] > TableOfBoostDash[d] and TableOfBoostDash[e] then
	if haveBoosted == false then
		local sa
		do dashsound
		do haveBoosted = true;
	elseif TableOfBoostDash[d] > TableOfBoostDash[c] and TableOfBoostDash[e] then
		if haveBoosted == false then
		local sb
		do dashsound
		do haveBoosted = true
	elseif TableOfBoostDash[e] > TableOfBoostDash[d] and TableOfBoostDash[e] then
		if haveBoostedDown == false then
		local sc
		do dashsound
		do haveBoostedDown = true;
		do haveBoosted = true;
		end
	end
end
The Second Question is, which = is this error referring to?:
Image

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Mon Mar 06, 2017 10:14 pm

You can't have multiple equals signs like that. You can do sa = player.speedX and/or player.speedX = -5 and/or sa = -5 but not sa = player.speedX = -5


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari