I am making a game in Flash CS6 with ActionScript 3.0, and my game can run properly but an error keeps popping up and I can't seem to solve it. The solutions I've found online aren't specific enough to my program.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at farmgame227_fla::MainTimeline/onenter()[farmgame227_fla.MainTimeline::frame2:133]
The line of frame two that is in question will vary depending on how I make the game end. Here are examples of the code in question.
import flash.events.Event;
addEventListener(Event.ENTER_FRAME,onenter);
var myscore = 0;
function onenter(e:Event)
{
if (sheep1.y < 0 || sheep1.y > 775 || sheep1.x < 0 || sheep1.x > 775)
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
if (hand.hitTestObject (goat))
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
score.text = myscore;
That isn't all of the code, but I just included the lines that seem to be in question with the debugger.
I have tried searching for multiple solutions to my problem, including debugging, but I can't seem to figure this out.
Thanks in advance.
Related
I have a Google Sheets table with a custom function. I have made a sanitized and reduced version of it here:
Google Sheet with Custom Function (CF)
The more rows I have in one tab, the more often I get the error:
"Error Internal error while executing the custom function."
Doing some research helped me to come to the conclusion that this issue is probably because the custom function is not used as a range formula as it is suggested here:
Optimizing Custom Functions
The custom function looks something like this:
function fifo(datesA, assetQtysA, transVolumesA, minHoldTime) {
//console.log("Original values: " + createCM({datesA, assetQtysA, transVolumesA, minHoldTime}));
var dates = [];
dates = Array.isArray(datesA) ? datesA : [datesA];
var assetQtys = [];
assetQtys = Array.isArray(assetQtysA) ? assetQtysA : [assetQtysA];
var transVolumes = [];
transVolumes = Array.isArray(transVolumesA) ? transVolumesA : [transVolumesA];
if (transVolumes.length === 0 || assetQtys.length === 0 || dates.length === 0) {
throw new Error('The transaction volumes, the asset quantities and the dates must each have at least one element!');
}
if (transVolumes.length !== assetQtys.length || transVolumes.length !== dates.length) {
throw new Error('The total transaction values, the asset quantities and dates must have the same amount of elements!');
}
if (assetQtys[0] < 0) {
throw new Error('The first transaction needs be a BUY transaction.');
}
//Something happening here ;-)
return [return_1, return_2, return_3, return_4, return_5, return_6];
Sorry, I'm not comfortable sharing the entire source code. But I hope you are able to understand.
So I'm trying to apply the range strategy (from the link above) on my special case, but have failed so far.
I have tried to apply this to the code, but I can't find my way out of multiple errors. I guess I'm on the wrong path here.
Anyone know how to manage this?
At least I hope after applying the range strategy the internal error message will disappear.
Many thanks for your help.
I know that this may sound a bit silly, but I am facing the situation as stated in the title. When I open the Xcode playground and test out the value, it is working as expected, there is nothing wrong. However, when part of my iOS code run it, the value becomes larger by one.
To illustrate clearer, part of the code looks something like the following (numberOfLists is an array):
if numberOfLists.count == 0 {
listIndex = Int16(0)
} else {
listIndex = Int16(numberOfLists.count)
}
print(listIndex)
When I print out the value of listIndex, when I expect it to be 0, it prints 1; when I expect it to be a certain positive integer, let's say, a, the printed value is a+1. It seems like the "+1" is consistent.
Has anyone encountered this situation before?
This code is for a modding engine, Unitale base on Unity Written in Lua
So I am trying to use a Boolean Variable in my script poseur.lua, so when certain conditions are met so I can pass it to the other script encounter.lua, where a engine Predefined functions is being uses to make actions happens base on the occurring moment.
I tried to read the engine documentation multiple times, follow the exact syntax of Lua's fonction like GetVar(), SetVar(), SetGobal(),GetGlobal().
Searching and google thing about the Language, post on the subreddit and Game Exchange and tried to solve it by myself for hours... I just can't do it and I can't understand why ?
I will show parts of my codes for each.
poseur:
-- A basic monster script skeleton you can copy and modify for your own creations.
comments = {"Smells like the work\rof an enemy stand.",
"Nidhogg_Warrior is posing like his\rlife depends on it.",
"Nidhogg_Warrior's limbs shouldn't\rbe moving in this way."}
commands = {"GREET", "JUMP", "FLIRT", "CRINGE"}
EndDialougue = {" ! ! !","ouiii"}
sprite = "poseur" --Always PNG. Extension is added automatically.
name = "Nidhogg_Warrior"
hp = 99
atk = 1
def = 1
check = "The Nidhogg_Warrior is\rsearching for the Nidhogg"
dialogbubble = "rightlarge" -- See documentation for what bubbles you have available.
canspare = false
cancheck = true
GreetCounter = 5
Berserk = false
encounter:
-- A basic encounter script skeleton you can copy and modify for your own creations.
encountertext = "Nidhogg_Warrior is\rrunning frantically"
nextwaves = {"bullettest_chaserorb"}
wavetimer = 5.0
arenasize = {155, 130}
music = "musAncientGuardian"
enemies = {"poseur"}
require("Monsters.poseur")
enemypositions = {{0, 0}}
-- A custom list with attacks to choose from.
-- Actual selection happens in EnemyDialogueEnding().
-- Put here in case you want to use it.
possible_attacks = {"bullettest_bouncy", "bullettest_chaserorb", "bullettest_touhou"}
function EncounterStarting()
-- If you want to change the game state immediately, this is the place.
Player.lv = 20
Player.hp = 99
Player.name = "Teemies"
poseur.GetVar("Berserk")
end
Thank you for reading.
The answer to my problem was to use SetGobal(), GetGobal().
For some reasons my previous attempt to simply use SetGobal()Resulted in nil value despite writing it like that SetGobal("Berserk",true) gave me a nill value error, as soon as I launch the game.
But I still used them wrong. First I needed to put it SetGobal() at the end of the condition instead of at the start of the the poseur.lua script because the change of value... for some reasons was being overwritten by it first installment.
And to test the variable in the function in my encounter.lua, I needed to write it like that
function EnemyDialogueStarting()
-- Good location for setting monster dialogue depending on how the battle is going.
if GetGlobal("Jimmies") == true then
TEEEST()
end
end
Also any tips an suggestions are still welcome !
Well firstly, in lua simple values like bool and number are copied on assignment:
global={}
a=2
global.a=a--this is a copy
a=4--this change won't affect value in table
print(global.a)--2
print(a)--4
Secondly,
SetGobal and the other mentioned functions are not part of lua language, they must be related to your engine. Probably, they use word 'Global' not as lua 'global' but in a sense defined by engine.
Depending on the engine specifics these functions might as well do a deep copy of any variable they're given (or might as well not work with complicated objects).
Always feel like I'm making something far more complicated than it has to be. I'm currently playing around with the WoW addon, Tongues, in hope of make a custom dialect filter - which is quite easy of course, very noob-friendly. At this point, there is one thing I want to accomplish-- something of which feels to have the implications far beyond this -- that is just novelty, but before I give up completely (lots of hours trying different things with no headway) I was hoping someone could come by, get a cheap laugh and perhaps help me fix this if they understand my point. And who knows, posting this new helpless questions might bump me up to being able to finally upvote!
Tongues.Affect["Drunk"] = {
["substitute"] = {
[1] = merge({
{ ["([%a]+)(%A*)$"] = "%1 ...hic!"},
Tongues.Affect["Slur"]["substitute"][1]
});
};
["frequency"] = 100;
};
What this does is simply add on the "...hic!" to sendchatmessage(); I believe it is. The frequency part seems completely broken and only the GUI slider in the game matters for that. What I was hoping to accomplish was to repurpose this and make the "...hic!" an actual randomized word. Since the mod itself handles the chance that it happens, I figured all that is needed left is to replace the string with a function=X. It's, of course, intensely way over my head, but despite checking the Lua of several mods, nothing feels like "it will fit."
The best I could come up with,
Tongues.Affect["TESTAFFECT"] = {
["substitute"] = {
[1] = merge({
{ ["([%a]+)(%A*)$"] = function(b)
local rand = Math.Random(1,2)
if (rand == 1) then
b = "test1"
return b
elseif (rand == 2) then
b = "test2"
return b
end
end
Leaves a gloriously useless message in the error mod BugSack - of course my attempt is wrong, but there's no way to know how!
I'm assuming this is enough information - as I said, very user friendly mod without any need to understand how it really works (Although I'd love to ready study it after this "project")
Anyone? Regardless, thank you for your time in simply even reading this far.
Update: Downvotes, okay! That's cool too. A little unpredictable, but sure. The error is as follows
15x Tongues\Core\dialects.lua:172: attempt to index field 'Affect' (a nil value)
Tongues\Core\dialects.lua:172: in main chunk
Locals:
175 in dialects.lua is
Tongues.Affect["Wordcut"]["substitute"][1],
Which has nothing to do with what I'm trying to accomplish, and works just fine.
Sorry that my question was an inconvenience. I asked to the best of my ability and the best of my ability to articulate the question proved to be less then stellar. The example codes I had provided were the only way I could articulate showing what I was trying to do.
I was misinterpreting the error frame and discovered that behind the useless stack that calls an error where there is, in fact, none, is a stack that calls the error in syntax at the time that broke it.
I'm sharing my results, regardless if the community finds this useless. I learned a tremendous amount from this personally, which is the only incentive in that I asked for help.
Tongues.Affect["TEST"] = {
["substitute"] = {
[1] = {
["([%a]+)"] = function(a)
return a
end;
["(%A*)$"] = function(a,b)
local rand = math.random(1,2)
if (rand == 1) then
b = "test1"
return b
end;
if (rand == 2) then
b = "test2"
return b
end;
end;
};
};
};
Hope it helps someone out there - as expected, I made it more complicated than it had to be. Simply "jiggling" the symbols is all that was needed.
I am using Lua with wxLua to build a GUI. Normally when I exit the app, I get no output from Lua.
However I just added a function to a wxListView (called myListView) like this
myListView.foo = bar
function bar (self)
-- do something with the wxListView
end
Whether or not I ever called foo(), when I exit the app, I get the following output from Lua:
~wxLuaObject -2 1 0
If I comment out the assignment, I get no output when exiting the app. If instead, I nil out foo later on in the code:
myListView.foo = nil
I get the same output immediately when that line is executed and then again on program exit.
What does the output mean? What am I doing wrong? How do I fix it?
Thanks!
This seems to be an internal diagnostic for the case when wxLuaObject is destroyed and m_reference == LUA_NOREF (-2 as it is in your case) and Lua state object is not in closing state (0 as reported in your case):
// this is from modules/wxlua/src/wxlbind.cpp (starts on line 83 in my version)
wxLuaObject::~wxLuaObject()
{
if ((m_reference != LUA_NOREF) && m_wxlState->Ok() && !m_wxlState->IsClosing())
{
m_wxlState->wxluaR_Unref(m_reference, &wxlua_lreg_refs_key);
m_reference = LUA_NOREF;
}
//else if (!m_wxlState->IsClosing())
// wxPrintf(wxT("~wxLuaObject %d %d %d\n"), (int)m_reference, (int)m_wxlState->Ok(), (int)m_wxlState->IsClosing());
I have this message commented out in my wxlua code (2.8.12.1), but you may want to check your version and upgrade as needed. This is the only place where ~wxLuaObject message appears in the source code. It seems to be harmless, but it can potentially point to other issues with what you are doing.