Good Morning (to those in an appropriate time zone),
I am creating a simple multi button scrolling menu (using widgets scrollView and button), however i’ve run into a snag involving references to my object
I am trying to create my scrollView and my buttons in a seperate file, while keeping the references for those widgets in another file so that i can destroy them at the end of a certain view.
I think the root of my problem is that my values are pass by value when i want them to be pass by reference.
Here is an example, lets make it a car one for fun, of whats causing the problem:
In one file
--main.lua require("displayManager.lua") require("listeners.lua") local displayObject = { ferrariManufacturerButton, maseratiManufacturerButton, } function displayMenu() local buttonFerrari = "Ferrari" local buttonFerrariLeft = display.viewableContentWidth/4 local buttonFerrariTop = display.viewableContentHeight/3 local buttonFerrariImage = "images/ManufacturerMenu/blueButton.jpg" local buttonWidth = 8\*30 local buttonHeight = 1 \* 30 createButton(displayObject.ferrariManufacturerButton, buttonFerrari, buttonFerrariLeft,buttonFerrariTop,buttonWidth, buttonHeight,buttonFerrariImage,manufacturerFerrariMenuListener) print(displayObject.ferrariManufacturerButton) -- returns nil :( end
while in my other file :
--displayManager.lua function createButton(buttonObject,buttonName, topLeft, topRight, bWidth,bHeight, buttonImage, listenerThing) local widget = require "widget" buttonObject = widget.newButton { left = topLeft, top = topRight, width = bWidth, height = bHeight, defaultFile = buttonImage, -- both textures for how to button looks pressed and released id = buttonName, onRelease = listenerThing } end
So unfortunately, my print statement in my main returns a value of nil. I dont like it to return a value of nil, because at some point when i call a new function to change the menu, i’d like to remove that object completely.
Though this example doesn’t show me creating a scrollView or placing the button in scrollView, the reason why i didn’t include it was because of a nil reference error i get to both my scrollView variable and my button variables because (of what I assume) is how i have my system currently set up
How should I proceed?