Implementing TFlers in my game - lua

i'm trying to design a game that was initially designed for 1680 x 1050.. however i implemented Tflers in my project and it not going that well.
First in my love.load i added:
function love.load()
TLfres.setScreen({w= 1680, h = 1200, full=true, vsync = false, aa=0}, 1, false, true)
end
Then in my love.draw():
function love.draw()
TLfres.transform()
love.graphics.setBackgroundColor(0,0,0)
if GameState == "MainMenu" then
love.graphics.draw(background,0,0)
love.graphics.draw(picture, 200, 200)
end
if GameState == "PaintGame" then
love.graphics.setBackgroundColor(20,191,243)
love.graphics.draw(easel, 640,360)
love.graphics.draw(cursor, love.mouse.getX(), love.mouse.getY())
end
TLfres.letterbox(16,9)
end
However i'm getting this error:
TLfres.lua.13: attempt to call field 'setMode' ( a nil value )
How to get rid of this error??
I realized that tlfres requires the old verison of love in order to work, however I want it on the newest version of love. how can I optimize it to work? Thanks!
Thanks guys!

I would add a comment, but I don't have enough reputation.
As of LÖVE 0.9.0, love.graphics.setMode was replaced with love.window.setMode. Talk with the library creator about that.

Related

Coding error in Pico 8 code (lua). (Newbie here)

I have recently started coding and wanted to try out Pico-8. A game development platform that uses Lua. I watched tutorials on how to create a platformer and have run into an obstacle with my code. Spid in the code is the name of my main sprite and i have organized some of the code into sections: init, update, draw, collisions and player. if anyone can help me with my error please may you keep in mind that i have little to no experience with coding.
Error message:
Runtime error line 26 tab 4
If spid.dy>0 then
attempt to index global 'spid' (a nil value)
at line 26 tab 4
Cart code
pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
--init
function _init()
spid={
sp=1,
x=59,
y=59,
h=8,
w=8,
dx=0,
dy=0,
maxdx=2,
maxdy=3,
acc=0.4,
boost=4,
anim=0,
running=false,
jumping=false,
falling=false,
crouching=false,
flp=false,
}
grav=1.2
friction=0.85
end
-->8
--update
function _update()
spid.x+=spid.dx
spid.y+=spid.dy
spid_update()
spid_animation()
end
-->8
--draw
function _draw()
cls()
spr(spid.sp,spid.x,spid.y,1,1,spid.flp)
map(0,0)
end
-->8
--collisions
function obj_collision(obj,aim,flag)
--obj = table and needs x,y,w,h
local x=obj.x local y=obj.y
local w=obj.w local h=obj.h
local x1=0 local y1=0
local x2=0 local y2=0
if aim=="left" then
x1=x-1 y1=y
x2=x y2=y+h-1
elseif aim=="right" then
x1=x+w y1=y
x2=x+w+1 y2=y+h-1
elseif aim=="up" then
x1=x+1 y1=y-1
x2=x+w-1 y2=y
elseif aim=="down" then
x1=x y1=y+h
x2=x+w y2=y+h
end
-- convert pixels to tiles
x/=8 y1/=8
x/=8 y2/=8
if fget(mget(x1,y1),flag)
or fget(mget(x1,y2),flag)
or fget(mget(x2,y1),flag)
or fget(mget(x2,y2),flag) then
return true
else
return false
end
end
-->8
--player
function spid_update()
spid.dy+=grav
spid.dx*=friction
end
if btn(2) then
spid.dx-=spid.acc
spid.running=true
spid.flp=true
end
if btn(1) then
spid.dx+=spid.acc
spid.running=true
spid.flp=false
end
if btnp(❎)
and spid.landed then
spid.dy-=spid.boost
spid.landed=false
end
if spid.dy>0 then
spid.falling=true
spid.landed=false
spid.jumping=false
end
if obj_collision(spid,"down",0) then
spid.landed=true
spid.falling=false
spid.dy=0
spid.y-=(spid.y+spid.h)%8
elseif spid.dy<0 then
spid.jumping=true
if obj_collision(spid,up,1) then
spid.dy=0
end
end
if spid.dx<0 then
if obj_collision(spid,"left",1) then
spid.dx=0
end
elseif spid.dx>0 then
if obj_collion(spid,"right",1) then
spid.dx=0
end
end
You have an extra end in your function on tab 4
I am assuming the end on the line after, spid.dx*=friction doesn't belong there. After correcting this pico-8 complains spid_animation() doesn't exist, which it doesn't in the code provided.
function spid_update()
spid.dy+=grav
spid.dx*=friction
end
if btn(2) then
spid.dx-=spid.acc
spid.running=true
spid.flp=true
end
May I suggest that you line up your if/end on the same column to keep them straight. This way it is much easier to look down the margin of your code and know which end's go with if statements, functions, etc.
for example, instead of:
if btn(2) then
spid.dx-=spid.acc
spid.running=true
spid.flp=true
end
use:
if btn(2) then
spid.dx-=spid.acc
spid.running=true
spid.flp=true
end
It seems like a small thing, but when you have a lot of nested code, it will make reading it much easier.
Pico-8 files may also be edited with external editors. I find this specially useful when running into issues like this (non-obvious bugs). For one you can see more of your code at once, and to they can highlight missing/extra end's.
Information on using an external editor is mentioned in the manual included with the executable: https://www.lexaloffle.com/pico-8.php?page=manual

GMOD Lua Use type doesn't matter?

recently I have been creating an imitation HarborRP gamemode for Garry's Mod, and I'm trying to recreate the Smuggler NPC (You'll know what I mean if you've ever played HarborRP) So basically I want the NPC to open ONE Derma-Frame window when the player presses their use key on it. I have the NPC created and all of that, but when the player simply presses their use key on the NPC, a million windows pop up, I have the NPC/Entity's use type set to SIMPLE_USE, but it seems like that doesn't matter because so many windows pop up. the VGUI/Derma Frame's settings is set to MakePopup() but that doesn't matter either. See if you can find whats wrong with it, I have very little knowledge of LUA.
init.lua file:
include("shared.lua")
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
util.AddNetworkString("smug")
hook.Add("PlayerUse", "menuu", function(ply, ent)
net.Start("smug")
net.Send(ply)
end)
function ENT:Initialize()
self:SetModel('models/humans/group01/female_01.mdl')
self:SetHullType(HULL_HUMAN)
self:SetHullSizeNormal()
self:SetNPCState(NPC_STATE_SCRIPT)
self:SetSolid(SOLID_BBOX)
self:SetUseType(SIMPLE_USE)
self:DropToFloor()
end
cl_init.lua file:
include("shared.lua")
function ENT:Draw()
self.Entity:DrawModel()
end
net.Receive("smug", function()
if( !frame ) then
local frame = vgui.Create("DFrame")
frame:SetSize(900,600)
frame:SetPos(ScrW()/2-450,ScrH()/2-300)
frame:SetVisible(true)
frame:MakePopup()
frame:SetDeleteOnClose(true)
elseif (frame) then print("HI")
end
end)
shared.lua file:
ENT.Base = "base_ai"
ENT.Type = "ai"
ENT.PrintName = "[DEV] Smuggler NPC"
ENT.Category = "InVaLiD's HBRP Entities"
ENT.Author = "InVaLiD"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.AutomaticFrameAdvance = true
Something To Note
All of these files are in the addons/smug_npc/lua/entities/ folder.
Yes, I know I have weird names for things, that's just me.
I have a basic to no knowledge of lua, so explain things please :)
I really do appreciate your help, and your will to help people, please know that I thank you all for being here just to sort other people's problems even though you could be spending your time doing something productive, Thank you!
You need to put your code that does net.Send into the entities ENT:Use function rather than on the PlayerUse hook.
function ENT:Use(ply)
net.Start("smug")
net.Send(ply)
end
The below line which you already have in your code in the initialize function makes the entity call the ENT:Use function once when a player presses E on it, which it seems that you want to do so that is good:
self:SetUseType(SIMPLE_USE)
Also, I recommend checking out the gmod forums if you need developer help in future.
GMod forums: https://gmod.facepunch.com/f

What causes "Tried to use a NULL physics object!" error in my Garry's Mod Lua script?

I've made a small script that makes ragdolls fly upwards. It works but it leaves an error message and I cant figure out why.
[ERROR] RunString:11: Tried to use a NULL physics object!
1. ApplyForceCenter - [C]:-1
2. fn - RunString:11
3. unknown - addons/ulib/lua/ulib/shared/hook.lua:179
The error is getting spammed in console until I delete all existing ragdolls
My code:
hook.Add("Think", "Fly", function()
ent = ents:GetAll()
for k, v in pairs(ent) do
local isRagdoll = v:IsRagdoll()
if isRagdoll == true then
phys = v:GetPhysicsObject()
phys:ApplyForceCenter(Vector(0, 0, 900))
end
end
end)
Thanks in advance.
Henrik's answer is spot on about logic. You do need to make sure the physics object is valid before trying to use it.
In GMod, the function for this is IsValid.
if IsValid(phys) then
I'd have added this as a comment to Henrik's answer but I don't quite have enough rep yet.
Edit: Thanks to MattJearnes for clarifying how to check gmod objects for NULL.
Without knowing anything about gmod's API, I'd guess that GetPhysicsObject can return a special value that depicts NULL, in which case you cannot call ApplyForceCenter on it. You should simply check for NULL before doing anything using IsValid:
hook.Add("Think", "Fly", function()
ent = ents:GetAll()
for k, v in pairs(ent) do
local isRagdoll = v:IsRagdoll()
if isRagdoll == true then
local phys = v:GetPhysicsObject()
if IsValid(phys) then
phys:ApplyForceCenter(Vector(0, 0, 900))
end
end
end
end)

Why is this code not starting?

I am trying to simulate a Simon Says game. I am currently using Corona SDK, and using Lua as my language.
I have put the addEventListener(touch) on the function, "starting". I have tried debugging it and it seems that the code does not correctly run the part that says, if (started) then statement. I would be very grateful if you guys were to help lead me to the right direction!
Here's part of my code:
local function starting(event)
if (started == false) then
started = true
end
if (event.phase == "ended") then
start()
startText.isVisible = false
---------------------------------------------------
--THIS BELOW PART IS WRONG-- does not do "started"
if (started) then
count = count + 1
--if started--
if(math.mod(count,20) == 0) then
clicked = 0
if(light >= 0) then
light = light - 1
end
end
Make sure you have initialized started as false like rpattiso mentioned. Also in my past experience with Lua, sometimes just putting if (started) then
does not work for me, so you should try if (started == true) then.

Using "\n" in Garry's Mod draw.DrawText

I want to make an admin-online list. I have the v:Nick() part down but I want to place a new line after it.
Example: (At the top right corner, the names are INSIDE OF EACH OTHER.)
I'm not sure how to go about it, I'm not a VGUI kind of guy, but I believe I have found a solution.
You could make a transparent panel with a DListView like this:
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 500, 700 )
DermaPanel:SetTitle( "Admins online" )
DermaPanel:SetVisible( false )
DermaPanel:SetDraggable( false )
DermaPanel:ShowCloseButton( false )
DermaPanel:MakePopup()
local DermaListView = vgui.Create("DListView")
DermaListView:SetParent(DermaPanel)
DermaListView:SetPos(25, 50)
DermaListView:SetSize(450, 625)
DermaListView:SetMultiSelect(false)
DermaListView:AddColumn("Name") -- Add column
DermaListView:AddColumn("Rank")
for k,v in pairs(ply:GetUserGroup() == "admin" or "superadmin" or "owner") do
DermaListView:AddLine(v:Nick(),v:GetUserGroup()) -- Add lines
end
Now all you have to do is a little ScrW() and ScrH() for re-sizing and you should be good to go!
Also, I got this code from https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexe102.html so I could save time, I would really recommend checking it out if you have a chance!
Hope I could help, Birdboat

Resources