farflamex's Forum Posts

  • Thanks for clearing that up. It's another little peculiarity of C2 which makes it very complicated when these problems pop up, especially since there's no debugger. Still, I know now, thanks.

  • There was a reason I didn't do this originally (because the tiles are also being created by other parts of the program) but I'm sure I can get around it by testing which screen I'm on for example. Thanks, I'll go with that - I'm banging my head against a brick wall with the above approach so I need to try something else anyway, and it does seem like a better solution here.

    Still confused as to why the code doesn't work though, it really should.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • And if you check the code again, forget all that stuff about UID's and objects, but can someone explain why that's not working? Look at what it does - the variable is set to -1. If the button is clicked, the object is created and the variable set to the UID (that part works and it does change the variable). Then it asks 'Is the variable NOT -1' and for some reason, it thinks it is. I don't see how that can be possible if I've just changed it to the UID of the new object.

  • Just to explain what I'm trying to do here.

    When the button is clicked, a new object is created. It can be one of 10 or so different objects, which are all in the same family. When they are created, they need a couple of variables set which are unique to that object, but then LOTS of variables set which are required for each type.

    So, what I wanted to do was, create the object, set it's variables, then find it in the family immediately and start setting all the standard variables. This part doesn't work in C2 - if you try to find it in the family at this point C2 doesn't find it because it's not registered until the next top-level event.

    So my solution (as mentioned on the forums for this kind of thing) is to create the object, do the couple of changes it needs, then save it's UID, start a new top level event, find it again in the family, then do all the other changes.

    The only alternative I'm seeing right now is to do the large number of changes for each object type, which would work but would be very laborious.

  • It's not attempting to play if the variable is -1, it attempting if it's NOT -1. In other words, if the variable was set to the UID above, then it should play.

    Also I can't use an else event here, remember this is stripped-down code and the reason I'm using this approach is that I need to work with the newly created object later on, but C2 won't allow that until you go back to a top-level event. This is a major problem I'm having regularly with C2. You need to either manipulate the object immediately inside the event-chain it was created in, or go back to a top-level event. So in this case, I'm storing the UID, then going to a top-level event and if the global variable has a UID stored instead of -1 it should play the sound.

    That's the code exactly as I'm running it, when I click the button, the variable is set to the new UID, meaning the sound should play in the next block, but it doesn't.

    I'll take a look into triggers, but I should point out that I'm aware that the code above isn't the best approach. I'm using this approach because I need to store the newly created object, then work with it in a new top-level event which is a C2 issue.

  • https://www.dropbox.com/s/ouo3me42a8ygh95/c2bug.png

    As you can see, the top line sets the variable to -1. If the mouse is clicked it then creates the new object and sets the variable to the new object's ID. It should then follow that the next line is actioned, since the variable is set to the UID so the sound should play, but it doesn't.

    Obviously this is very simplified, but I can confirm that it doesn't work and the sound is fine elsewhere. The reason I'm doing seperate 'Is layer visible' top-level events is because the code is more complex than this but it requires that to get the new object to register.

  • That's the problem really, workflow is not linear when it comes to creating new objects. You need to back up to a new top-level event before it registers. It's a real pain and constantly causing me problems. My solution here is messy and it doesn't even work.

    With a GV, does it IMMEDIATELY alter? Will the new value be in place regardless of the indentation of the next check etc? Is it something to do with minus numbers? I'm clutching at straws here but this just makes no sense. I'll try to strip some code out and post a screenshot.

  • There must be something I don't understand about how GV's behave in C2 because mine isn't behaving as I'd expect.

    I have my global variable, and I set it to -1 every loop. If an object is created, I set the GV to the object's UID, so that I can then retrieve the UID later on and work with the new object (I'm doing this because of the issue where a newly created object doesn't become accessible until a new top-level event... it's necessary in my case).

    So I then do a test, which is basically saying, if my GV is NOT -1, a new object was created, so I can work with it. But for some reason, when I set the GV and then test it, it doesn't respond.

    So like this.

    Every tick - GV = -1

    Event - Create object and set GV to the new UID.

    Next top-level event - If GV <> -1, do stuff.

    It doesn't work. When a GV is altered, is it altered immediately or do I need to wait for new events or something?

  • Yeah I guess that would work. It's already in a family but I suppose you could do another family just for this purpose? Cheers, hadn't thought of that.

  • Yeah, basically, what we WANT is something like the VB debugger, where you can step through, line by line and check which line it's on and the values of variables. But then again, that's the best debugger I've worked with and I understand that it'd be difficult, if not impossible, to implement.

    In general I find C2 to be very good to use and it massively increases productivity. Unfortunately on bugs, I'm finding they're far harder to find than a normal programming language. It's sometimes next to impossible to work out which events are even being processed. Even a basic debugger would be nice.

  • That was just an example really, my own code is a bit more complex. This all needs to happen internally, not something that can be worked around on the screen. I basically need to know how I can test an object against all of the other objects of the same type, since once you've picked an object, how can you then pick all the others and compare them against the first?

  • A simplified version of what I'm trying to achieve.

    I have a 7x7x7 grid and I need to make sure that only one of a certain object can occupy a grid location.

    So I pick my object, decide where I want to put it, then I need to check all of the other objects to make sure they're not in that same location. Since I've already picked one object, I'm not sure how to repick them all without losing my first pick - and since I've already picked one object, I can't pick the whole lot now anyway.

    So my attempt to solve this was to create a 7x7x7 array, do a loop where each object puts a '1' in the place it's occupying, then when I place the new object, compare against the array. If there's a 1 there, it's occupied.

    For some reason that I can't fathom that doesn't work.

    I may be overcomplicating this, any ideas?

  • I'm in desperate need of a debugger in C2. I'm spending hours and hours staring at lines of code and realising that I don't understand how C2 is interpreting them, since they 'should' work. I need a line-by-line stepper to see what's going on since this is now taking up most of my time. I'm resorting to sounds (a beep next to the actions so I can hear if they're even being reached) and text object to output numbers, but I'm still having real difficulties. But I guess if it's not feasible in C2... well it's making me think I need to find a different language, which is a shame because C2 is amazing in every other respect.

  • Yeah, that'd do the trick, better than my plan to have a local variable just count down. C2 could use a 'step' counter though in my opinion.

    Thanks :)

  • Is it possible to loop backwards in a For Loop? i.e Step -1 from other languages? I can't see anything in the manual.