I'm blocked

0 favourites
From the Asset Store
Physics Block Puzzle game template for Construct 3
  • Hi,

    I'm lost about pass values from / to another action. I need some help so I'm blocked.

    1) I want recover the value from an "touched" object and store globally.

    2) From these globally value I want "repeat for each key" and from the values that I found I want perform some action, color change for example over the objects values.

    I'm blocked I read the manuals, search the forum but I don't have idea how handle it.

    The 1) is ok. I have a instance variable with the name of the sprite and when I "touch" I set the value to a instance variable of the dictionary. But no more...

    How can I do the point 2) ?

    Thanks in advance.

    Salut,

    Josep M

  • You are building a game board risk type game right?

    Take a bit of time and watch this

    Subscribe to Construct videos now

    .

    Edit: the videos will explain more, and in more detail than I ever could

  • Yes. I try it

    Thanks for answer and point me...

  • Hi,

    Well, after view the videos I understand the use of containers and how select the zones using others frames.

    In my case then I will have a unselected and a selected image of each zone. All the zones are different so I don't know if is better put all the zones inside a container. So each sprite must be assigned with her own triggers, isn't?

    Salut,

    Josep M

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • JosepM

    1 sprite for zones. With instance variable active. Drag that sprite out for each zone. place into container with city name. add touch and watch the magic. Construct2 is super smart. Each zone sprite will take on the characteristics of the origanal. But it is smart can detect which is being touched. I added a text box which shows which sprite is being touched (id) and city which is part of that sprite, and changed image to reflect active.

    So container you will drop everything related to city (marker, name, units, whatever) and drag and place them where you want them. You want to re-use objects not clutter your game with 1000's

    Example is Pretty basic, but will help you on your way.

  • Hi DUTOIT,

    Many thanks for your example, finally I was able to put my map working. Attach the .capx so maybe can be usefull to anybody.

    Few questions more.

    1)Why the city tokens select also the zone? I touch the city and the zone react to the touch. The city pass the event to the bottom elements? Can be blocked?

    2)How call a function from other event sheet? If I add a the function into other event sheet the call doesn't work, or I don't have idea how call it.

    3)Can be used with an array to stablish the destinations from a select zone?

    Zone 1: 2,7,6

    Zone 2: 1,3,6,7

    Zone 3: 2,4,6,7

    Zone 4: 3,5,7,6

    Zone 5: 4,7,6

    Zone 6: 1,2,3,4,5

    Zone 7: 1,2,3,4,5

    So when I touch a zone I get the NameID check the array and with repeat for each element assign the frame, but I don't know how assign the sprite to the frame inside the repeat so each sprite is diferent.

    Thought?

    Salut,

    Josep M

  • Quick reply, as I don't have much time.

    1) put a condition that touching zone isn't touching sprite.

    the X is right click and invert which means opposite of what condition is saying.

    See image attached -

    [attachment=2:1yi0gpd9][/attachment:1yi0gpd9]

    touch X(is not) touching sprite then do this...

    2) Make one main event sheet and include all event sheets into it.

    [attachment=1:1yi0gpd9][/attachment:1yi0gpd9]

    3) I think I understand what you are saying, but I'm getting old and not as sharp as I wish I was.

    You can do this, and there are number guys who have more knowledge about this than me.

    I usually hardcode everything. Or, use invisible textboxes with data that I can retrieve. Or on startup save data into instance variables.

    THen use foreach sprite.... bla bla bla

    look system > loops >

    Each sprite has unique id, and each sprite can have instance variables that you can save data to that is unique to that sprite.

    I used something similiar to tutorial using custom paths using waypoints. Don't have link offhand.

    It uses instance variable to store waypoints.

    Here is capx from tutorial:

    [attachment=0:1yi0gpd9][/attachment:1yi0gpd9]

    Hope that helps a bit

    Edit: look at this demonstrates sort of what I am saying.

  • Hi DUTOIT

    I explain with more detail what I want to accomplish.

    Now I have the “hard coded” version of the map definition, I mean that I defined for each zone the posibles destinations in “touch event”. Thank you for your tips.

    I want that these posibles destinations will be drive through an array. For each zone I have an array with the posibles destinations, so when the user “touch” one zone, I want repeat for each element of their array and change the frame, so maintain the zones connectors will be more easy.

    Pseudocode.

    Load from an URL or file the JSON of the arrays for each zone.

    Zone #A touched
    if active=true of Zone #A
    repeat for each element X of array #A
    	Change frame of zone X
    	Set active =true
    end repeat [/code:1b0usnav]
    
    On this way I can update the zones destinations from an array and not by “hard code”
    
    It’s posible do that? how can I refer to a sprite inside the repeat loop?
    Can I pass sprite reference to a function?
    I read about the UIID but don’t know how pass it?
    
    Salut,
    Josep M
  • Hi DUTOIT

    I explain with more detail what I want to accomplish.

    Now I have the “hard coded” version of the map definition, I mean that I defined for each zone the posibles destinations in “touch event”. Thank you for your tips.

    I want that these posibles destinations will be drive through an array. For each zone I have an array with the posibles destinations, so when the user “touch” one zone, I want repeat for each element of their array and change the frame, so maintain the zones connectors will be more easy.

    Pseudocode.

    Load from an URL or file the JSON of the arrays for each zone.

    Zone #A touched
    if active=true of Zone #A
    repeat for each element X of array #A
    	Change frame of zone X
    	Set active =true
    end repeat [/code:1r099xrj]
    
    On this way I can update the zones destinations from an array and not by “hard code”
    
    It’s posible do that? how can I refer to a sprite inside the repeat loop?
    Can I pass sprite reference to a function?
    I read about the UIID but don’t know how pass it?
    
    Salut,
    Josep M
    

    Load from json using ajax works perfectly.

    sprite.uid / sprite.iid gives you the unique id of the sprite. But I don't like to use this.

    My preferred way is to create an instance variable and name each one, that way I can control the assigned number.

    And you can retrieve it, condition it, manipulate it etc etc easy enough.

    Point is. You can now check against the array.

    So if instance variable = to any of the array numbers then sprite frame 2 to highlight possible moves, or whatever.

    You need the instance variables to use in conditions, especially when moving pieces, highlighting active/non active etc etc.

    UID/IID should never be hardcoded.

    So if zones destinations (instance variables) = array possibles destinations then ...[do this, or that]

    Don't hold me to this:

    But instance var

    City Name: London

    Zone: 1

    Section: 1

    City Name: Paris

    Zone: 1

    Section: 2

    Array

    Zone1

    :: 1

    :: 2

    Zone2

    ::1

    ::2

    if zone.zone = 1 (this automatically selects all sections)

    if you want specif section, then add another condition if zone.section = 2 (this narrows it down to paris)

    So foreach zone...

    Condition: zone.zone = 1

    change frame bla bla bla

  • [attachment=0:1fk56efc][/attachment:1fk56efc]@JosepM,

    Very Basic example.

  • Hi DUTOIT,

    I test your example and is good, but the problem I see is that my regions are each one a sprite, my map is a colletion of sprites and no instances of the same sprite, so how can I refer to each one from inside the repeat loop?

    For the chips stats and others elements that can be instances is very good.

    Salut,

    Josep M

  • JosepM

    Bundle them up using families. And assign instance variable to families...

    So for each families...

    condition: instance variable bla bla

    etc etc

    Edit:

    You need to make use of of entire toolset, from families to containers. and instance variables. With turn based and movement you have to keep track of lots of data, so you need more tools for the job.

    I'm all ears for simpler way. When you start moving pieces, having pieces overlap others, having multiple players, and tons of sprite objects. Instance variables are the only way I can safely assign unique data to various objects.

    With a unique id and data, you can then save to array/dictionary/ and ultimately to webstorage (save points)

    All ears if you come up with simpler solution - shrugs.

  • JosepM

    Afterthought:

    You say you got lots of objects(images) for each piece of map etc.

    You are adding those pieces to frames right? Object Sprite called world map, and each frame is country etc.

    So all under one sprite object which has instance variables. You drag image and set the initial frame...

    [attachment=0:3olqa60l][/attachment:3olqa60l]

    That way you can have map with multiple frames of individual pieces. etc etc etc

  • Hi DUTOIT,

    Nop, my initial approach is create the map with many sprites where each sprite is a region, country, etc.. and each frame show the region selected and with some colors of each faction.

    As you said me, group all the region sprite into families permit me loop to select automatically the destinations from the selected region and as you said before load from a JSON into an array to control it.

    {"Z1":[2,6,7],"Z2":[1,3,6,7],"Z3":[2,4,6,7],"Z4":[3,5,6,7],"Z5":[4,6,7],"Z6":[1,2,3,4,5],"Z7":[1,2,3,4,5]}

    But the array don't recognize the JSON array. Is correct? or I missing something?

    How handle it from one worldmap sprite?

  • {
    "c2array":true,
    "size":[6,5,1],
    "data":
    [
       [   ["Z1"],      [2],[6],[7],[9]            ],
    [/code:3jcnaszw]
    I don't know why, but C2 requires the "c2array":true part etc.
    
    Best bet is to create array using c2, then download it on start of layout. THen check the downloaded file as frame of refrence.
    One big map... I used image points, which can be effective. But breaking it up like you said is also good. 
    Done both ways, each with pro's / cons.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)