Assign private var value... [solved]

This forum is currently in read-only mode.
  • I have a question again.

    I have a private variable on a menu item that I try to assign a value, according to when characters are obtained.

    It should work like this: if slot1 = 0, then it will be assigned the value. But if not 0, slot2 will get the value instead, and so on and so forth... So far I put it up like this:

    <img src="http://img.photobucket.com/albums/v194/Vatina/example.jpg">

    (too lazy to make an example .cap right now)

    But when I run the debugger, I can see that the value in slot1 is still overwritten when I obtain the second character, instead of moving on to slot2 :S I tried a few variations as you can see, without luck.

    Any better suggestions?

  • It looks like your actions all set slot1 to 1 in every event, so slot2 is never set. From what you wrote t appears that this isn't the intended behavior.

  • Well, in "obtainElli" it is always supposed to set them to one, and in "obtainSheila" (partly visible in the bottom) it should be 2.

    But if one of the slots is taken, it should move on to the next. Fx slot1 = 1 and you obtain Sheila, then slot2 should get 2. But in my case it still enters 2 into slot1 even though it was already filled.

    I hope that makes sense. My code is probably overly complicated for what it is supposed to do <_<

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • As Davioware pointed out, the code above doesn't seem to allow what you describe that you want it to do.

    It's difficult to figure out a code fragment like that without knowing what happens before or after with this data, though...

    If you have six character slots, and you want each newly available character to be added to the first open slot (apparently as a unique number), then you should be setting the same slot as you are checking in each event, and also include a 'no open slots' case if that is possible.

    On function "ObtainElli":
    
        'slot1' <= 0 : set 'slot1' to 1
    
        else 'slot2' <= 0 : set 'slot2' to 1
    
        else 'slot3' <= 0 : set 'slot3' to 1
    
        ... etc ...
    
        else 'slot6' <= 0 : set 'slot6' to 1
    
        else : call function("noRoomLeftInParty")
    [/code:2cjhgygj]
    
    Then it would seem that the next "ObtainCharacter" function should set each to 2 instead of 1. If this is how it should work, then you could do this with one function that accepts a parameter for the number to set the first empty slot to, and call it with a different number for each character.
  • Finally back...

    I tried what you said and used "else", but it still doesn't work. Here is example cap I made of it all:

    http://www.mediafire.com/?3jc0g4uv4amzuye

    I'm a bit hopeless in trying to built this character menu. If anyone has any suggestions for better ways of doing it, I'd be interested of course.

    The "member number" variable is intended to be used in the menu as well, so that construct remembers which member was clicked, and opens a new menu accordingly. At least that's the plan...

    Edit: Oh my... I tried thinking of how to do this from the very bottom, and have found a different way that actually works. The members show up correctly in my menu now.

    Thanks for chiming in though Until next time, heh.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)