function Team_Swap()
local Backg = vgui.Create( "DFrame" )
Backg:SetSize( ScrW() / 2, ScrH() / 2 )
Backg:SetPos ( ScrW() / 2, ScrH() / 2 )
Backg:SetTitle( "Swap Teams" )
Backg:SetVisible ( true )
Backg:SetDraggable ( true )
Backg:ShowCloseButton ( true )
Backg:MakePopup()
local DColorButton = vgui.Create ( "DColorButton", Backg )
DColorButton:SetPos( 40, 40 )
DColorButton:Paint( 100, 40 )
DColorButton:SetSize( 100, 40 )
DColorButton:SetText( "Join Red Team", Color( 221,78,76 ) )
DColorButton:SetColor( Color( 221,78,76 )
function DColorButton:DoClick(player)
player:Kill()
player:SetTeam(1)
player:Spawn()
end
end
concommand.Add( "set_team", Team_Swap )
This code runs fine... until you do its only purpose CLICK THE BUTTON
the button when clicked returns the following text in console
newrecycle]set_team
[ERROR] gamemodes/capturetheflag/gamemode/cl_init.lua:32: attempt to index local 'player' (a nil value)
1. DoClick - gamemodes/capturetheflag/gamemode/cl_init.lua:32
2. unknown - lua/vgui/dlabel.lua:218
[n3wr3cycl3|20|STEAM_0:1:59994487] Lua Error:
[ERROR] gamemodes/capturetheflag/gamemode/cl_init.lua:32: attempt to index local 'player' (a nil value)
1. DoClick - gamemodes/capturetheflag/gamemode/cl_init.lua:32
2. unknown - lua/vgui/dlabel.lua:218
please help!
First of all: You are mixing Clientside (vgui) and Serverside (Player:SetTeam()) Stuff.
(Explanation why you are running in this Error is in the Clientside Script)
My suggestion:
Clientside Script:
function Team_Select()
local Backg = vgui.Create( "DFrame" )
Backg:SetSize( ScrW() / 2, ScrH() / 2 )
Backg:SetPos ( ScrW() / 2, ScrH() / 2 )
Backg:SetTitle( "Swap Teams" )
Backg:SetVisible ( true )
Backg:SetDraggable ( true )
Backg:ShowCloseButton ( true )
Backg:MakePopup()
local TeamRedButton = vgui.Create ( "DColorButton", Backg )
TeamRedButton:SetPos( 40, 40 )
TeamRedButton:Paint( 100, 40 )
TeamRedButton:SetSize( 100, 40 )
TeamRedButton:SetText( "Join Red Team", Color( 221,78,76 ) )
TeamRedButton:SetColor( Color( 221,78,76 )
function TeamRedButton:DoClick() -- DoClick has 0 Params
RunConsoleCommand("switchteam", "red")
end
end
concommand.Add( "chooseteam", Team_Select )
And Serverside Script:
function Team_Switch( --[[ Player ]] player, --[[ String ]] cmd, --[[ Table ]] args)
-- Get the Parameter out of the Table (in my example "red" for the red team)
-- and move the player to the choosen Team
end
concommand.Add("switchteam", Team_Switch)
The Clientside Script is just the GUI for the user. The actual Teamswitch is handled by the server and can be initialized from the Client console as well.
The user is able to execute switchteam red directly
Source: My Experience and the GMod Wiki
Related
I'm trying to spawn asteroids in this game every few seconds. But whenever I run the game, I get an error that says
stack traceback:
main.lua:277: in function '_listener'
?: in function '?'
?: in function <?:172>
I've tried moving some of the code around but it's not helping. My professor looked at my code and doesn't know exactly what the issue is, but that the loop that I'm using is missing a something. Here is all the code that includes "createAsteroid"
EDIT: I added my entire main.lua file to this question. The separate files that I do have in this project are the character and the background image, everything else besides the config file is in here. I did try deleting an extra end In the gameLoop function but when I did, I got an error that basically said it expected an end there.
display.setStatusBar( display.HiddenStatusBar )
------------------------------
-- RENDER THE SAMPLE CODE UI
------------------------------
local sampleUI = require( "sampleUI.sampleUI" )
local physics = require( "physics" )
physics.start()
math.randomseed( os.time() )
------------------------------
-- CONFIGURE STAGE
------------------------------
local composer = require( "composer" )
local mainScene = display.newGroup()
display.getCurrentStage():insert( mainScene )
----------------------
-- BEGIN SAMPLE CODE
----------------------
-- Frequently used variables
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local originX = display.screenOriginX
local originY = display.screenOriginY
local width = display.actualContentWidth
local height = display.actualContentHeight
local score = 0
local died = false
local asteroidsTable = {}
local player
local gameLoopTimer
local scoreText
local uiGroup = display.newGroup() -- Display group for UI objects like the score
-- Load background and character from "background.lua" and "character.lua" respectively
local background = require( "background" )
mainScene:insert( background )
local character = require( "character" )
mainScene:insert( character )
local asteroid = display.newImage( "asteroid.png", 180, -50 )
asteroid.rotation = 5
physics.addBody( asteroid, { density=3.0, friction=0.5, bounce=0.3, radius=25 })
-------------------------
-- BEGIN MOVEMENT LOGIC
-------------------------
-- Movement logic variables
local movementSpeed = 1.5
local moving = false
local moveDirection = "down"
-- Sets if the character should move and updates sprite animation
local function setMoving( state )
moving = state
if ( moving ) then
character:play()
else
character:pause()
character:setFrame(2)
end
end
-- Sets the direction that the player should move and updates the character's sprite facing
local function setMovementDirection( direction )
-- Don't change anything if we haven't altered direction
if ( moveDirection == direction ) then
return
end
-- Update the sprite playback
moveDirection = direction
character:setSequence( "walk-" .. direction )
-- Refresh animation playback, which can pause after changing the sprite sequence
setMoving( moving )
end
-- Set movement magnitudes
local movementX = 0
local movementY = 0
local function setMovement( x, y )
local updatedMovement = false
-- Horizontal movement checks
if ( movementX ~= x and nil ~= x ) then
movementX = x
updatedMovement = true
end
-- Abort if nothing is updating
-- We do this since axis/key events can fire multiple times with the same values
if ( not updatedMovement ) then
return
end
-- Determine movement direction
if ( 0 ~= movementX or 0 ~= movementY ) then
-- Favor horizontal animations over vertical ones
if ( math.abs( movementX ) >= math.abs( movementY ) ) then
if ( 0 < movementX ) then
setMovementDirection( "right" )
else
setMovementDirection( "left" )
end
else
if ( 0 < movementY ) then
setMovementDirection( "down" )
else
setMovementDirection( "up" )
end
end
end
-- Update moving animation/variable
if ( 0 == movementX and 0 == movementY ) then
setMoving( false )
else
setMoving( true )
end
end
-- Handle character translation on the screen per frame
local function onFrameEnter()
if ( 0 ~= movementX ) then
character.x = character.x + ( movementSpeed * movementX )
setMoving( true )
end
if ( 0 ~= movementY ) then
character.y = character.y + ( movementSpeed * movementY )
setMoving( true )
end
end
Runtime:addEventListener( "enterFrame", onFrameEnter )
---------------------------
-- BEGIN INPUT CODE: TOUCH
---------------------------
local padGraphic, padButtonUp, padButtonDown, padButtonLeft, padButtonRight
-- Determine if we have a joystick connected or not
local inputDevices = system.getInputDevices()
local function getHasJoystick()
for i = 1, #inputDevices do
if ( "joystick" == inputDevices[i].type ) then
return true
end
end
return false
end
local hasJoystick = getHasJoystick()
-- If we don't have any controllers found, create a virtual D-pad controller
if ( not hasJoystick ) then
-- Called when one of the virtual D-pad buttons are used
local function onTouchEvent( event )
local phase = event.phase
local targetID = event.target.id
if ( "began" == phase or "moved" == phase ) then
if ( "up" == targetID ) then
setMovement( 0, -1 )
elseif ( "down" == targetID ) then
setMovement( 0, 1 )
elseif ( "left" == targetID ) then
setMovement( -1, 0 )
elseif ( "right" == targetID ) then
setMovement( 1, 0 )
elseif ( "padGraphic" == targetID ) then
setMovement( 0, 0 )
end
elseif ( "ended" == phase or "cancelled" == phase ) then
-- An alternative to checking for "cancelled" is to set focus on the control
-- However, we don't want an incoming phone call to bug out input
if ( "up" == targetID or "down" == targetID ) then
setMovement( nil, 0 )
elseif ( "left" == targetID or "right" == targetID ) then
setMovement( 0, nil )
end
end
return true
end
-- Display score
scoreText = display.newText( uiGroup, "Score: " .. score, 400, 40, native.systemFont, 36 )
-- Hide the status bar
display.setStatusBar( display.HiddenStatusBar )
local function updateText()
scoreText.text = "Score: " .. score
end
local function createAsteroid()
local newAsteroid = display.newImageRect( mainGroup, objectSheet, 1, 102, 85 )
table.insert( asteroidsTable, newAsteroid )
physics.addBody( newAsteroid, "dynamic", { radius=25, bounce=0.8 } )
newAsteroid.myName = "asteroid"
local whereFrom = math.random( 3 )
if ( whereFrom == 1 ) then
-- From the left
newAsteroid.x = -60
newAsteroid.y = math.random( 500 )
newAsteroid:setLinearVelocity( math.random( 40,120 ), math.random( 20,60 ) )
elseif ( whereFrom == 2 ) then
-- From the top
newAsteroid.x = math.random( display.contentWidth )
newAsteroid.y = -60
newAsteroid:setLinearVelocity( math.random( -40,40 ), math.random( 40,120 ) )
elseif ( whereFrom == 3 ) then
-- From the right
newAsteroid.x = display.contentWidth + 60
newAsteroid.y = math.random( 500 )
newAsteroid:setLinearVelocity( math.random( -120,-40 ), math.random( 20,60 ) )
end
newAsteroid:applyTorque( math.random( -6,6 ) )
end
-- Create the visuals for the on-screen D-pad
local padSize = 200
padGraphic = display.newImageRect( mainScene, "pad.png", padSize, padSize )
padGraphic.x = originX + padSize/2 - 40
padGraphic.y = height + originY - padSize/2 + 40
padGraphic.alpha = 0.35
padGraphic.id = "padGraphic"
padGraphic:addEventListener( "touch", onTouchEvent )
-- Creates one of the invisible virtual D-pad buttons
local function createPadButton( buttonID, offsetX, offsetY )
local btn = display.newRect( mainScene, padGraphic.x+offsetX, padGraphic.y+offsetY, padSize/5, padSize/5 )
btn:addEventListener( "touch", onTouchEvent )
btn.id = buttonID
btn.isVisible = false
btn.isHitTestable = true
return btn
end
-- Create buttons for handling the D-pad input
padButtonUp = createPadButton( "up", 0, padSize/-5 )
padButtonDown = createPadButton( "down", 0, padSize/5 )
padButtonLeft = createPadButton( "left", padSize/-5, 0 )
padButtonRight = createPadButton( "right", padSize/5, 0 )
end
-----------------
-- GAME LOOP --
-----------------
local function gameLoop()
-- Create new asteroid
createAsteroid()
-- Remove asteroids which have drifted off screen
for i = #asteroidsTable, 1, -1 do
local thisAsteroid = asteroidsTable[i]
if ( thisAsteroid.x < -100 or
thisAsteroid.x > display.contentWidth + 100 or
thisAsteroid.y < -100 or
thisAsteroid.y > display.contentHeight + 100 )
then
display.remove( thisAsteroid )
table.remove( asteroidsTable, i )
end
end
end
timer.performWithDelay(1000, gameLoop, 0)
--------------------------------------------------
-- BEGIN INPUT CODE: KEYBOARD & BASIC CONTROLLER
--------------------------------------------------
-- Detect if a joystick axis is being used
local joystickInUse = false
-- Keyboard input configuration
local keyUp = "up"
local keyDown = "down"
local keyLeft = "left"
local keyRight = "right"
-- Called when a key event has been received
local function onKeyEvent( event )
local keyName = event.keyName
local phase = event.phase
-- Handle movement keys events; update movement logic variables
if ( not joystickInUse ) then
if ( "down" == phase ) then
if ( keyUp == keyName ) then
setMovement( nil, -1 )
elseif ( keyDown == keyName ) then
setMovement( nil, 1 )
elseif ( keyLeft == keyName ) then
setMovement( -1, nil )
elseif ( keyRight == keyName ) then
setMovement( 1, nil )
end
elseif ( "up" == phase ) then
if ( keyUp == keyName ) then
setMovement( nil, 0 )
elseif ( keyDown == keyName ) then
setMovement( nil, 0 )
elseif ( keyLeft == keyName ) then
setMovement( 0, nil )
elseif ( keyRight == keyName ) then
setMovement( 0, nil )
end
end
end
return false
end
Runtime:addEventListener( "key", onKeyEvent )
------------------------------------------
-- BEGIN INPUT CODE: ADVANCED CONTROLLER
------------------------------------------
-- We only support advanced controllers when one is detected
if ( getHasJoystick ) then
-- Detect axis event updates
local function onAxisEvent( event )
local value = event.normalizedValue
local axis = event.axis.type
local descriptor = event.axis.descriptor
-- We only care about "x" and "y" input events
-- However, touch-screen events can fire these as well so we filter them out
if ( ( "x" ~= axis and "y" ~= axis ) or ( string.find( descriptor, "Joystick" ) == nil ) ) then
return
end
-- Detect zero movement at a certain cutoff so we don't get the character moving very, very slowly
if ( math.abs(value) < 0.15 ) then
value = 0
end
-- Based on which axis type we are dealing with, set movement variables
if ( "x" == axis ) then
setMovement( value, nil )
elseif ( "y" == axis ) then
setMovement( nil, value )
end
-- Some devices will send both up/down/left/right keys and the axis value
-- We let our code know that we are using a joystick value so they do not conflict
if ( 0 ~= value ) then
joystickInUse = true
else
joystickInUse = false
end
end
Runtime:addEventListener( "axis", onAxisEvent )
end
local function onCollision( event )
if ( ( obj1.myName == "player" and obj2.myName == "asteroid" ) or
( obj1.myName == "asteroid" and obj2.myName == "player" ) )
then
display.remove( player )
else
ship.alpha = 0
timer.performWithDelay( 1000, restoreShip )
end
end
Runtime:addEventListener( "collision", onCollision )
Go to line 277 in your file main.lua
You will find a function call createAsteroid(). Within this scope createAsteroid is not defined.
So let's see if we can find a definition for createAsteroid in this file.
Line 218: local function createAsteroid() ...
Check if the function call is within the scope of that function...
No! It is inside an if-statement while the function call is outside that statement. As createAsteroid is local to that if-statement it is unknown (nil) inside gameLoop and hence may not be called.
Finding such scope issues could be very easy if you had proper indentation!
I was trying to make a simple videogame for smartphones, well, what i'm now trying to do is that when i click on the 'volMusicTickOn' object, this must disappear and the music stops. I've done this with a function listener but i got an error on calling the listener, here's the code:
local settings = composer.newScene()
local particlesTable = {}
local particlesGroup = display.newGroup()
local options =
{
width = 600,
height = 600,
numFrames = 2,
sheetContentWidth = 1200,
heetContentHeight = 600
}
local tickSheet = graphics.newImageSheet( "rectTick_sheet.png", options )
--
--
function settings:create( event )
-- Dichiarazione oggeti e codice eseguibile
num=0
local sceneGroup = self.view
background = display.newImageRect( sceneGroup, "background.png", 1280 , 720 )
background.x = display.contentCenterX
background.y = display.contentCenterY
volMusicTickOn = display.newImageRect( "rectTick_on.png", 100, 100 )
volMusicTickOn.name = "volMusicTickOn"
volMusicTickOn.x = display.contentCenterX - 250
volMusicTickOn.y = display.contentCenterY - 100
end
function settings:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == "did" ) then
if event.phase=="began"then
end
if event.phase=="ended"then
end
end
end
function settings:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == "did" ) then
-- Code here runs when the scene is entirely on screen
end
end
function settings:destroy( event )
local sceneGroup = self.view
end
-- Funzioni
local function remove(particle)
display.remove( particle )
table.remove( particlesTable, num)
end
local function removeParticle( particle )
timer.performWithDelay(1000, transition.to( particle, {alpha=0, time=350, onComplete=remove(particle) } ))
end
local function removetotally( particle )
display.remove( particle )
table.remove( particlesTable, num )
end
function dimParticle( particle )
transition.to( particle, {alpha=0, time=500, onComplete = removetotally, onCompleteParams = particle})
end
local function generateParticles()
local xy=math.random(30,70)
local newParticle = display.newImageRect( particlesGroup, objectSheet , chooseColor(math.random(3)), xy, xy )
table.insert( particlesTable, newParticle )
num = num+1
newParticle.x = (math.random(1280)*math.random(88932))%1280
newParticle.y = (math.random(720)*math.random(13546))%720
newParticle.alpha = 0
transition.to( newParticle, {alpha=1, time=150, onComplete=dimParticle, onCompleteParams=newParticle})
end
local function generateParticlesSmall()
local xy=math.random(5,15)
local newParticle = display.newImageRect( particlesGroup, objectSheet , 1, xy, xy )
table.insert( particlesTable, newParticle )
num = num+1
newParticle.x = (math.random(1280)*math.random(88932))%1280
newParticle.y = (math.random(720)*math.random(13546))%720
newParticle.alpha = 0
transition.to( newParticle, {alpha=1, time=150, onComplete=dimParticle, onCompleteParams=newParticle})
end
local function chooseColor(n)
if n==1 then
return 8
elseif n==2 then
return 9
elseif n==3 then
return 10
end
end
function changeMusicVolumeStatus(event)
if audio.isChannelPaused( 1 ) then
audio.resume( 1 )
else
audio.pause( 1 )
end
return true
end
local function changeEffectsVolumeStatus(event)
if audio.isChannelPaused( 2 ) then
audio.resume( 2 )
else
audio.pause( 2 )
end
return true
end
-- Chiamate e Listener Del Runtime
bigPTimer1=timer.performWithDelay( 1, generateParticles, 0 )
bigPTimer2=timer.performWithDelay( 1, generateParticles, 0 )
smallPTimer=timer.performWithDelay( 1, generateParticlesSmall, 0 )
settings:addEventListener( "create", settings )
settings:addEventListener( "show", settings )
settings:addEventListener( "hide", settings )
settings:addEventListener( "destroy", settings )
volMusicTickOn:addEventListener( "tap", changeMusicVolumeStatus )
volMusicTickOff:addEventListener( "tap", changeMusicVolumeStatus )
--
return settings
Here is the error i got
16:49:45.126 ERROR: Runtime error
16:49:45.126 C:\Users\lpasi\Downloads\Progetto 1-20170725T134427Z-001\Progetto 1\settings.lua:167: attempt to index global 'volMusicTickOn' (a nil value)
16:49:45.126 stack traceback:
16:49:45.126 [C]: in function 'error'
16:49:45.126 ?: in function 'gotoScene'
16:49:45.126 C:\Users\lpasi\Downloads\Progetto 1-20170725T134427Z-001\Progetto 1\menu.lua:36: in function '_onRelease'
16:49:45.126 ?: in function '?'
16:49:45.126 ?: in function <?:654>
16:49:45.126 ?: in function <?:169>
I've tried to use also table listeners but nothing changed, pleas lemme know if you solve my problems, Thank You.
Are you sure settings:create is called before you try to reference volMusicTickOn? Because settings:create defines volMusicTickOn and thus it will be nil until it is called.
As I see it, the create event may not be fired until after you reference volMusicTickOn for the first time. Your code, because it is event based, is not guaranteed to run what this line sets up:
settings:addEventListener( "create", settings )
Before this line:
volMusicTickOn:addEventListener( "tap", changeMusicVolumeStatus )
volMusicTickOff:addEventListener( "tap", changeMusicVolumeStatus )
And this, volMusicTickOn might be nil
The solution would be to actually move those lines into settings:create so you know that volMusicTickOn is not nil for sure!
I attempt to get data (in a global variable) from user through a textbox from the user in functions, and use these variables to insert into a sqlite table.
But, when I attempt to do so, I get an error like "attempt to call global locationGlobal (a nil value)" in the INSERT INTO line, after I click the submit button.
NOTE : I input values in the textbox by using Bluestacks android simulator as inputting the text is not possible in windows Corona SDK.
Here is my code :
local widget = require("widget")
require "sqlite3"
local path = system.pathForFile("testUser.db", system.DocumentsDirectory)
db = sqlite3.open( path )
--local location,area,arrivalTime,departTime,eventAttended
local function onSystemEvent( event )
if( event.type == "applicationExit" ) then
db:close()
end
end
--local tablesetup = [[CREATE TABLE IF NOT EXISTS visitPlace (id INTEGER PRIMARY KEY autoincrement, location, area, arrivalTime, departTime, eventAttended);]]
local tablesetup = [[CREATE TABLE place (id INTEGER PRIMARY KEY autoincrement, location);]]
print(tablesetup)
db:exec( tablesetup )
_W = display.viewableContentWidth
_H = display.viewableContentHeight
local background = display.newRect(0,0,_W,_H)
background:setFillColor(0,0,0)
local function textListenerLocation( event )
if ( event.phase == "began" ) then
-- user begins editing defaultField
event.target.text = ''
print(location)
print( event.text )
elseif ( event.phase == "ended" ) then
-- do something with defaultField text
locationGlobal = tostring( event.target.text)
elseif ( event.phase == "editing" ) then
print( event.newCharacters )
print( event.oldText )
print( event.startPosition )
print( event.text )
elseif ( event.phase == "submitted" ) then
locationGlobal =tostring( event.target.text)
--local label = display.newText( location, 180, 30, native.systemFontBold, 20 )
-- label:setFillColor( 190/255, 190/255, 1 )
end
end
local function SubmitEvent( event )
--local label = display.newText( location, 180, 30, native.systemFontBold, 20 )
--label:setFillColor( 190/255, 190/255, 1 )
local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,']]..locationGlobal..[[) ]]
db:exec(insertionTable)
for row in db:nrows("SELECT * FROM visitPlace") do
local text = row.location
local t = display.newText(text, 450, 120*row.id, native.systemFont, 40)
t:setFillColor(1,0,1)
end
local label1 = display.newText( "Submitted", 180, 30, native.systemFontBold, 20 )
label1:setFillColor( 190/255, 190/255, 1 )
end
function background:tap( event )
native.setKeyboardFocus(nil)
end
local locationTxtbox = native.newTextField(180,140,280,100)
locationTxtbox.size = 34
locationTxtbox:addEventListener("textListenerLocation",locationTxtbox)
local submitButton = widget.newButton
{
label = "Submit",
onEvent = SubmitEvent,
shape = "roundedRect",
width = 100,
height = 30,
cornerRadius = 2
}
submitButton.x = display.contentCenterX + (display.contentCenterX/2)
submitButton.Y = display.contentCenterY + (display.contentCenterY/2)
background:addEventListener("tap",background)
Runtime:addEventListener( "system", onSystemEvent )
--defaultField = native.newTextField( 150, 150, 180, 30 )
--defaultField:addEventListener( "userInput", textListener )
currently your textlistenerlocation function is not being called. So when you hit the submit button, locationGlobal has not yet been defined.
The following looks suspicious:
locationTxtbox:addEventListener("textListenerLocation",locationTxtbox)
the addEventListener should take an event string and then a function to call when the event happens. textListenerLocation is your event handling function, it is not the event string.
locationTxtbox:addEventListener("userInput", textListenerLocation)
I am having problems with my Lua. I an making a MOTD for my server using HTML that I am going to host with my website.
I have my frames set up and the according tabs, as seen
But this is my problem
As you exit the MOTD by pressing 'accept', the page set in the code stays up as seen and invades your screen like hell. My code is as follows:
function Welcome ()
MainMenu = vgui.Create( "DFrame" )
MainMenu:SetPos( 350, 100 )
MainMenu:SetSize( 1200, 900 )
MainMenu:SetTitle( "Welcome Menu" )
MainMenu:SetBackgroundBlur( true )
MainMenu:SetVisible( true )
MainMenu:SetDraggable( true )
MainMenu:ShowCloseButton( false )
MainMenu:MakePopup()
PropertySheet = vgui.Create( "DPropertySheet")
PropertySheet:SetParent( MainMenu )
PropertySheet:SetPos( 5, 30 )
PropertySheet:SetSize( 1190, 820 )
local DermaButton = vgui.Create( "DButton", DermaPanel )
DermaButton:SetText( "Agree" )
DermaButton:SetSize( 165, 30 )
DermaButton:SetPos( 590, 860 )
DermaButton:SetParent( MainMenu )
DermaButton.DoClick = function()
MainMenu:Close()
RunConsoleCommand( "say", "I have read and agree with the rules")
end
local DermaButton = vgui.Create( "DButton", DermaPanel )
DermaButton:SetText( "Disagree" )
DermaButton:SetSize( 165, 30 )
DermaButton:SetPos( 420, 860 )
DermaButton:SetParent( MainMenu )
DermaButton.DoClick = function()
MainMenu:Close()
surface.PlaySound( "buttons/button8.wav" )
RunConsoleCommand( "say", "I disagree with the rules, I will now be disconnected.")
RunConsoleCommand( "disconnect" )
end
local TabOne = vgui.Create( "DPanel" )
TabOne:SetVisible( true )
local HTML = vgui.Create("HTML")
HTML:SetPos(50,50)
HTML:SetSize(ScrW() - 100, ScrH() - 100)
HTML:OpenURL("http://www.garrysmod.com")
local TabThree = vgui.Create( "DPanel" )
TabThree:SetVisible( true )
local HTML = vgui.Create("HTML")
HTML:SetPos(50,50)
HTML:SetSize(ScrW() - 100, ScrH() - 100)
HTML:OpenURL("http://www.garrysmod.com")
local TabTwo = vgui.Create( "DPanel" )
TabTwo:SetVisible( true )
local HTML = vgui.Create("HTML")
HTML:SetPos(50,50)
HTML:SetSize(ScrW() - 100, ScrH() - 100)
HTML:OpenURL("http://www.garrysmod.com")
local TabFour = vgui.Create( "DPanel" )
TabThree:SetVisible( true )
local HTML = vgui.Create("HTML")
HTML:SetPos(50,50)
HTML:SetSize(ScrW() - 100, ScrH() - 100)
HTML:OpenURL("http://www.garrysmod.com")
local TabFive = vgui.Create( "DPanel" )
TabThree:SetVisible( true )
local HTML = vgui.Create("HTML")
HTML:SetPos(50,50)
HTML:SetSize(ScrW() - 100, ScrH() - 100)
HTML:OpenURL("http://www.garrysmod.com")
PropertySheet:AddSheet( "Home", TabOne, "gui/silkicons/heart",
false, false, "Welcome to the server!" )
PropertySheet:AddSheet( "Rules", TabTwo, "gui/silkicons/script",
false, false, "Server rules!" )
PropertySheet:AddSheet( "Group", TabThree, "gui/silkicons/group",
false, false, "Group page!" )
PropertySheet:AddSheet( "Ranks", TabFour, "gui/silkicons/flag_blue",
false, false, "Ranks and donations!" )
PropertySheet:AddSheet( "Admins", TabFive, "gui/silkicons/shield",
false, false, "Your admin squad!" )
end
concommand.Add("OpenMotd", Welcome )
If you need to contact me fast, I can be found on Steam, under steamcommunity.com/id/PonyTerrance
This is happening, because you are not closing the HTML object anywhere in the code.
Also remember, that you are creating multiple HTML objects with the same variable name - Either choose an unique variable name for each one or simply create one HTML object and remove the other code passages which are creating HTML objects.
First time post and I sincerely apologize if this has been answered in any other post but I have not been able to find a resolution for the problem I'm facing on this or any other site. I'm a new programmer self-teaching with web tutorials and any other resource I have found. I am trying to create code which will spawn characters and allow you to call them. I've had trouble assigning an index value to the individual instances I have created with a for function. I have tried to establish the instance as both a table and a group display object. If anyone is able to point me in the direction of any resources to get a more indepth understanding of tables and group display objects for the Corona SDK implementation of Lua I'm sure that my problem is that I don't have a thorough enough understanding of these particular functionalities and how they work. Here is the code I've written so far.
-- Character Game
require "sprite"
require "ui"
local background = display.newImage("Background Placeholder.png")
halfW = display.viewableContentWidth / 2
halfH = display.viewableContentHeight / 2
local numCharacters = 20
local roundedRect = display.newRoundedRect( 365, 20, 110, 40, 8 )
roundedRect:setFillColor( 0, 255, 0, 80 )
score = 0
t = ui.newLabel{ bounds = { 370, 30, 100, 40 },
text = "Score " .. score,
textColor = { 255, 0, 20, 255 },
size = 18,
align = "center"
}
local scoreboard = function ( event )
t:setText( "Score " .. score )
end
Runtime:addEventListener( "enterFrame", scoreboard )
local group = display.newGroup()
local character = sprite.newSpriteSheetFromData( "Character Placeholder.png", require("Character Placeholder").getSpriteSheetData() )
local characterSet1 = sprite.newSpriteSet(character,1,8)
sprite.add(characterSet1,"character",1,8,1500,0)
local characterplay = function( event )
score = score + group.points
group[i]:removeSelf()
end
do
for i=1, numCharacters do
group:insert(sprite.newSprite(characterSet1))
group[i].xScale = .2
group[i].yScale = .2
group.points = 50
group[i]:setReferencePoint ( display.BottomCenterReferencePoint )
group[i]:translate( halfW + math.random( -100, 100 ), halfH + math.random( -130, -110 ) )
end
timer.performWithDelay( 500, charactermovie )
for i=1, 21 do
timer.performWithDelay( math.random( 500, 5000 ) , charactermove )
charactermove = function(event )
transition.to( group[i], { time=10000, y = 580 } )
transition.to( group[i], { time=8000, x = math.random( 0, 480 ) } )
transition.to( group[i], { time=7000, xScale = 1.5} )
transition.to( group[i], { time=7000, yScale = 1.5} )
group[i]:prepare("character")
group[i]:play()
end
group[i]:addEventListener( "tap", characterplay )
end
end
charactermovie = function( event )
group[i]:prepare("character")
group[i]:play()
end
local function spriteListener( event )
print( "Sprite event: ", event.sprite, event.sprite.sequence, event.phase )
end
for i, group in pairs(group) do print (group, i, v) end
I'm currently getting an "attempt to index field '?' at the line containing this code "group[i]:addEventListener( "tap", zombieplay )" upon launch and a "nil key supplied for property lookup" error at the "group[i]:removeSelf()" line of the "zombieplay" function. I've tried moving the offending code to a variety of locations to see if this is a scoping issue but I largely run into the same error and believe I may not properly understand indexes and keys... I've found that the app functions as intended but I have to call index keys 1 through 21 to get them all to move even though I am only calling for 20 characters and the removeSelf line throwing errors is not removing the individual characters. I'm going to try writing a module for the characters and see if that helps clear any of this up. I will post my results shortly.
Your characterplay and charactermovie functions are trying to use the variable i, this is outside the functions scope.
There is a property of event called target, which is used to get the event callee. You want to do something like this:
local characterplay = function( event )
score = score + group.points
event.target:removeSelf()
end