Jump to content


Photo

Unknown variable id


  • Please log in to reply
2 replies to this topic

#1 Elouj

Elouj

    GMC Member

  • New Member
  • 96 posts

Posted 04 April 2012 - 04:41 PM

In a collision event, right after a child might be born,

When the child is born I get its id like so:
child = instance_create(x,y,object_index)


Afterwards it adds it to the mother's memory which is held in a string:
if species = maternal and child != noone
{
    maternalstring = string_insert(string(child.id),maternalstring,0)
}

Why is it throwing an unknown variable id, when I just made the child and got its id, and checked again just to make sure that child != noone?

Just in case it was being destroyed in the same instant I put it above the child bearing code and told it not to add the id unless told to by the child bearing code, so that it would run next step.
like so:

if species = maternal and child != noone and childcheck = true
{
    maternalstring = string_insert(string(child.id),maternalstring,0)
    childcheck = false
}

//checking if it should make a child and stuff here.
{
    child = instance_create(x,y,object_index)
    childcheck = true
}

Then I decided to do something odd just in case and came up with this:
if childcheck = true
{
    with (child)
    {
        if variable_local_exists("id")
        {
            other.childcheck = true
        }
        else
        {
            other.childcheck = false
        }
    }
}

if species = maternal and child != noone and childcheck = true
{
    maternalstring = string_insert(string(child.id),maternalstring,0)
    childcheck = false
}

//checking if it should make a child and stuff here.
{
    child = instance_create(x,y,object_index)
    childcheck = true
}
It still randomly throws the unknown variable id error though, how do I get it to only try to add its id to the string if it actually has an id?

There seems to be no rhyme nor reason to when it appears and when it does not.
Situations in which it will both appear, or not appear according to chance:
First contact
First contact after children have been born
A random contact when no children have been born
A random contact after children have been born.
A random contact after children have been born and contacts had already happened previously where they had not been born.
A random contact after children had been born with contacts between when children were not born.

I have no idea why it is appearing, and why it is appearing when it is.

Edited by Elouj, 04 April 2012 - 05:09 PM.

  • 0

#2 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 1484 posts
  • Version:GM8.1

Posted 04 April 2012 - 05:13 PM

I do not know why it throws that error, but it isn't necessary to use child.id since child is the id value itself, so you can just simply use child without the .id
  • 0

#3 Elouj

Elouj

    GMC Member

  • New Member
  • 96 posts

Posted 04 April 2012 - 05:17 PM

I tried that but it did not add the id to the string for some reason the first couple times I tried it that way, strangely now it does, I guess that solves my problem, someday I want to know why there was a problem in the first place, and why just using string(child) did not work, yet now does. Thank you for getting me to try it again just in case.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users