Page 49 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Fri Feb 24, 2017 10:29 am
by PixelPest
Take a look at NPC.getIntersecting()

Re: Need help with lua? - LunaLua General Help

Posted: Fri Feb 24, 2017 11:12 am
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Feb 24, 2017 9:43 pm
by ssumday
Thank you very much! Colliders.lua is exactly what I needed.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Feb 27, 2017 10:35 pm
by Quantumenace
Is there a way to access the profiler lag data with lua (the stuff that shows up when you push F3)?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Feb 28, 2017 2:50 am
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Feb 28, 2017 3:36 am
by Quantumenace
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Feb 28, 2017 1:32 pm
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Feb 28, 2017 3:07 pm
by Quantumenace
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.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Mar 01, 2017 2:58 am
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Mar 01, 2017 10:31 am
by Angelus
What can I do regards camera with LunaLua? Can I increase the camera update speed, so the transition is faster?

Re: Need help with lua? - LunaLua General Help

Posted: Wed Mar 01, 2017 10:32 am
by Emral
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?

Re: Need help with lua? - LunaLua General Help

Posted: Wed Mar 01, 2017 10:34 am
by Angelus
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?

Re: Need help with lua? - LunaLua General Help

Posted: Wed Mar 01, 2017 10:53 am
by PixelPest
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)

Re: Need help with lua? - LunaLua General Help

Posted: Wed Mar 01, 2017 11:00 am
by Angelus
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.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Mar 01, 2017 11:07 am
by Quantumenace
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.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Mar 03, 2017 3:53 am
by Quantumenace
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Mar 05, 2017 10:09 pm
by PersonNamedUser
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

Re: Need help with lua? - LunaLua General Help

Posted: Sun Mar 05, 2017 10:23 pm
by PixelPest
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

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 06, 2017 9:57 pm
by PersonNamedUser
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

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 06, 2017 10:14 pm
by PixelPest
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