randomly's Forum Posts

  • You are actually right. I was mistaken.

    I used the Multiplayer object in many games, but never encountered this issue...

    Anyways, let's solve this with the host then.

    If you want to message a peer, you will need to add his ID to the message you are sending to let the host know who has to receive the message.

    There are multiple ways to do this:

    Option 1 | Adding the ID to the message:

    Add the ID after the message and separate them with escaping character.

    The host would then need to parse that message (e.g. with Regex) and send the appropriate message to the peer.

    This could look like this:

    Peer who wants to PM:

    Send message "pm":  [message] & "//" & [recipientID] (to host)[/code:16mfd0o6]
    [b]Host:[/b]
    The host needs to parse the message.
    [code:16mfd0o6]On peer message "pm":
    --- Send message {
    ----------- Peer ID:     RegexMatchAt(Multiplayer.Message, "\d+\D+\/{2}(\d+\D+)","",0)
    ----------- Message:  RegexMatchAt(Multiplayer.Message, "(\d+\D+)\/{2}\d+\D+","",0)
    --- }[/code:16mfd0o6]
    (I won't explain Regex to you, there are many tutorials out there, if you want to learn it. If you don't want to learn it or dislike Regex in general, see Option 2)
    
    [u]Option 2, using a Dictionary[/u]
    This option uses a simple 2-key dictionary that contains the recipient's ID and the message in two separate keys.
    The peer will send this dictionary as JSON to the host who will then load the JSON into his own dictionary to easily parse its contents to send the PM.
    
    This could look like this:
    
    [b]Peer who wants to PM:[/b]
    [code:16mfd0o6]Dictionary "pm": Clear
    Dictionary "pm" : Add key "ID" with value "[recipientID]"
    Dictionary "pm": Add key "msg" with value "[message]"
    Send message tag "pm" with content [Dictionary]pm.AsJSON (to host)[/code:16mfd0o6]
    [b]Host:[/b]
    [code:16mfd0o6]On message "pm":
    -- Dictionary "pm": Load from JSON [Multiplayer.Message]
    -- Send message  {
    -------- ID: [Dictionary]pm.Get("ID")
    -------- Message: [Dictionary]pm.Get("msg")
    -- }[/code:16mfd0o6]
    
    ___________________________________
    
    I'm not 100% sure about the Regex method, it [i]should[/i] work though.
    The dictionary method will definitely work, if executed correctly.
  • [quote:3m3sgb9r]I want players to be synchronized on that and the timer to be displayed for them.

    I would just have the host broadcast one single message that will start a timer for the peers.

    Just use the "timer" behavior and start that when receiving the host's message.

    Of course, this will be client-dependant but less tedious than regularly sending a variable.

    You could also start a "timer" behavior for the host and use the "duration" expression minus the "currentTime" expression to broadcast the remaining time.

    That would make the dictionary obsolete.

    _________________________________

    [quote:3m3sgb9r]And here is the latest .capx : https://www. dropbox.com/s/i9d67roqu2jtql6/ChatProject.capx?dl=0

    Link doesn't work for me. 404.

    (Yes, I removed the blank space)

    ______________________________________

    [quote:3m3sgb9r]Arf, actually it doesn't work with the "Group" value. I think I am doing something wrong with the "send message" action.

    Actually, I think that this

    For peer : On peer message, tag "Group", set "Group" to "Multiplayer.Message"[/code:3m3sgb9r]
    is the issue.
    Try changing the "group" value to [i]int(Multiplayer.Message)[/i].
    See my previous post:
    
    This will convert numbers or anything else to a string so you can e.g. send it via Multiplayer.
    [b]Just remember to convert it back when receiving a message if needed.[/b]
    
    
    Btw, as a future tip:
    try to test whether messages are actually received with a simple debugging text object before changing the actions/methods.
    (Just add a text object and change it to "Multiplayer.Message" on Peer message to check whether the host or peer is the issue)
    
    ___________________________________
    
    [quote:3m3sgb9r]And since that did not work, I tried to first save "Multiplayer.FromID" in a global variable or in a dictionary and sending to that value instead, but it doesn't work either.
    
    Chuck that. Isn't really necessary since the expression already works as a global variable of some sort.
  • Yeah the thing is, the whole system uses XML, so I can't just simply use a variable since I would have to combine the variable with the XML which would be quite tedious.

    What I can do though, is add a dictionary that counts the amount of every text object and combine that with the rest.

    Though I still think that my solution isn't very effective, but it was the only thing I could come up with.

  • [quote:2hrs6vvv] I'm keeping it very simple right now and using twelve 50 by 50 px sprites filled with dark grey stacked on top of each other to create the vertical bar.

    Actually, this is very ineffective.

    I'd recommend using a Tiled Background or a 9-patch and scale it instead of using separate Sprites.

    That will also make the height-definition easier and more fluent.

    Anyways, if you still want to use your Sprite version after reading this, just give me a shout and I'll figure sth. out.

  • [quote:2zk2tulv]OK, I found that if I disable uBlock Origin it works. Is there anything I can do about this in my game to make sure it works for uBlock users?

    Huh, that's awkward. I use uBlock too....

    And as I mentioned, I don't have any issues on either sites..

    I probably can't help you anymore here, since I just know stuff about C2, but not about browsers...

  • The simplest option would be to not send it to the host but rather to the peer you actually want to PM.

    To do this, you need to know the Peer's ID. But the ID is easy to get if you know his Multiplayer Alias.

    Just use Multiplayer.PeerIDFromAlias(PeerName).

    Now you just need to add an event to the peer group that handles messages with the tag "private" as private messages.

  • [quote:3117olom]What's also weird is when I upload it to the scirra arcade it is totally fine the first time you play but if you refresh the page it stops working

    First of all, this doesn't happen to me.

    Works perfectly after reloading the page.

    Must be a local issue.

    _______________________________________

    [quote:3117olom]When I run my game preview in a browser it works perfectly fine, but when I export it and upload it it stops working! I get a blank screen and can only hear audio. You can try it here: http://robert-kent.com/trainerwreck/

    Also, this doesn't happen when I open the link.

    There are some white flashes on the screen when the enemies collide with the server, but neither does the screen stay white nor does a blank screen appear.

    And when I opened your .capx, I saw that the short flashes are intended.

    The issues you encounter seem to be connected to your browser, since it works perfectly for me.

    (Btw, I'm using Waterfox, a modified version of Firefox)

  • Currently, there is no way to do this with the "Scroll To" behaviour.

    But you can do the following:

    • Remove the ScrollTo behaviour
    • Add an event "Every tick"
    • Under that event, add the action "System: Scroll to position
    • As X and Y, insert the X and Y coordinates of your player. Now, you can add the offset

    This could look like this:

    Every tick:
    -----Scroll to    Player.X+50 ,  Player.Y
    [/code:vbuw0rm6]
  • Here you go:

    Download .capx

    Important:

    This is a very rough and unfinished version, not very backend-friendly.

    It is not commented, so it probably is quite confusing.

    I don't have the time to comment it yet, so I will add that later.

    You will also have to understand XML to understand how the program works.

    You won't need it though to add new recipes, since XML is easy to edit.

    There is also one quite big issue:

    Recipes with more than one ingredient of the same kind (like Sharp Stone, 2xStone) will be crafted with one ingredient only and will cause other recipes with the same ingredient to stop working correctly.

    I'll probably address this in the future, if you can't fix it yourself.

    It is possible, but quite tedious.

    This is my first use of XML in a project, so keep in mind that there might be better solutions than the one I used.

    You may want to bump this thread if you think you need more help.

  • Just to let you know, I'm working on an example for you.

    By the way, it's in XML, I think that's more suiting for a crafting system than an Array.

  • [quote:1b7rhigt]Apparently, there is a problem with sending a variable as a message.

    Try wrapping a "str()" tag around the global variable.

    So that the message is 'str(variable)'.

    _____________________________________________-

    [quote:1b7rhigt]As you can see in my .capx, I already have a "Creatures" family with all the sprites in it

    Tried to look at your .capx, your file doesn't exist anymore under the link you posted.

    Please update the link.

    ____________________________________________

    [quote:1b7rhigt]I tried your idea of "picking "Creature" by evaluating "Index = Spawn" but that did not work

    This is exactly how it should work.

    Put the whole family in the picking event and set the condition as "Self.Index = [your_variable]".

    If that doesn't work, then it's the Spawn variable that is the problem.

    _____________________________________________

    [quote:1b7rhigt]But that wouldn't work since "Groupgenerator.Next" is a number and not a string (damn, that limitation is troublesome).

    I see, you are not familiar with "str()" and "int()" yet.

    You can remove number or string limitations by putting "str()" or "int()" around your variable.

    So when the expression needs to be a number, use "int(variable)".

    This will automatically take all the numbers that are in the string and make a number out of that.

    When you need a string, use "str(variable)".

    This will convert numbers or anything else to a string so you can e.g. send it via Multiplayer.

    Just remember to convert it back when receiving a message if needed.

    _________________________________________

    [quote:1b7rhigt]Here is another idea I just tried, but it failed (too bad! I was confident this time ah ah) : I created a "GlobalValues" dictionnary. The host task is to add a "Timer" key every second with the value "Timer" (global variable's current value), and add a key "Group" on peer connected, with the value "GroupGenerator.Next". Then, broadcast a message every second, tag "Timer", message "GlobalValues.Get(Timer)" and send a message on peer connected, ID "Multiplayer.FromID", tag "Group", message "GlobalValues.Get(Group)". For the peers : on peer message, tag "Timer"/"Group", set "Timer/Group" (Global variable) to "Multiplayer.message".

    May I ask what the "timer" variable is for?

    And what the exact purpose of the dictionary and the whole process around it is?

    I don't seem to grasp it yet.

    Broadcasting and using dictionary values shouldn't be too hard, so if you tell me what the purpose of it is, I can help you with it more easily.

    [quote:1b7rhigt]Then, broadcast a message every second, tag "Timer", message "GlobalValues.Get(Timer)"

    Also, why don't you just broadcast the variable directly?

    Why does it have to be in the dictionary first?

    ________________________________________________________

    [quote:1b7rhigt]But I have troubles with this whole "host transforms into JSON > send to peers > Peers transform back to dictionnary objet" process. I think I would need a concrete example on that one.

    As simple as this:

  • We definitely need either your .capx or a screenshot of your event sheet to solve this,

    since this is no common problem but a specific issue.

  • Okay, without the .capx, this will be a bit more difficult. But I understand that your project is quite big already and cutting it properly will take long.

    Anyways, as I said, debugging from the distance is quite hard.

    So let's start some tests.

    • Did you try not restarting the layout on death, but instead scrolling to the start point?
    • Do you have any other events that set "stagearea"?
    • You probably already looked at "stagearea" in the debug view right? If you didn't yet, go ahead and see how and whether it changes when entering rooms
    • Try adding "Trigger once while true" to the last condition in your screenshot. Just to make sure, this isn't what causes the problem

    That's about everything I can think of now without looking at the .capx.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry that I didn't reply earlier.

    I don't get a notification when you edit your post without mentioning my username.

    Let's go through your questions one by one:

    From the first post:

    [quote:30npxdth]I see no way to ask for the "first" value in the meaning of "the first of the randomly generated string of value" but only in the meaning "lowest possible value (the opposite of end value)"

    [quote:30npxdth]asking for the "next" value for the first time will actually give the first value in the string

    Since Smart Random's Expression "next" starts at the minimum of the second value and only "start" returns the first value, you won't be able to simply always use "next".

    I suppose you use a function.

    You will call the function with the parameter of the random number index you want.

    (If you want the first random number, call the function with parameter 1, for the second, choose parameter 2 and so on)

    The function itself will check what the parameter ( Function.Param(0) ) is.

    If it is 1, it will set the function's return value to "SmartRandom.Start".

    If it is bigger than 1, it will set the function's return value to "SmartRandom.Next".

    Like this, you can simply call this function with the appropriate parameter when you need a new random number.

    _______________________________________

    [quote:30npxdth]Actually I have trouble now I am using families

    Try this .capx I created:

    Capx Download

    _________________________________________

    From the second post:

    [quote:30npxdth]I can't find a way to synchronize the "timer" global value. Everybody should have the host "timer", but I see no way to broadcast a number value.

    When the "timer" value is changed by the host, add an action "Multiplayer: Broadcast message".

    • From ID: Leave this like it is, since "" indicates that the message comes from the host, which is what we want
    • Tag: Change to what you like, for example "timer"
    • Message: Obviously, you put your global variable in this.
    • Mode: Leave this like it is too. This is only really important for real-time games (e.g. Multiplayer Shooter)

    Also, make sure that you add an event for the peers:

    "Multiplayer: On message "timer": Set timer to: 'Multiplayer.Message'".

    And make sure, no other action apart from this changes the global variable when you aren't the host.

    __________________________________

    [quote:30npxdth]I can't find a way to send to each peer, upon connection

    There are multiple ways to do this.

    First of all,

    add this event:

    "Multiplayer: On peer connected".

    This triggers when somebody joins the same room.

    Then, under that event, you can save the ID of the player that just connected or any other information you want by using "Multiplayer.From____" (e.g. FromID, FromAlias). This will return the information of the peer that just connected.

    Instead, you could also use "Multiplayer: PeerAliasAt(PeerCount-1)/PeerIDAt(PeerCount-1).

    This will return the same values since the player that just connected has to be the most recent player in the room and therefore, this will return his information. ("-1" since PeerAliasAt needs an index which starts at 0 and the PeerCount starts at 1)

    When you saved those values (to a dictionary, for example), you can send the needed information, e.g. the group number, to this peer using the aforementioned values.

    You need to add an action "Multiplayer: Send message" under the "On peer connected" event.

    As the peer ID, use the values mentioned above.

    The rest is the same as above.

    (Note: you don't have to save the ID/Alias, but it might be useful later)

    __________________________________________

    [quote:30npxdth]Is there a way to simplify the list of 30 events for spawning creatures using family ?

    See the .capx I posted above.

    _________________________________________________________-

    [quote:30npxdth]I feel like dictionnaries and arrays will come in handy here, but I am not yet familiar with those. Anyway, next step will be implementing the scoring system, so I will have to learn about it quite soon.

    Just tell me where you need help if the C2 manual didn't help you.

    Dictionary manual entry

    Array manual entry

    ________________________________________________________

  • cristiart

    Since r240, this error always happens for me when launching C2.

    I don't know what it causes, but I simply press "Retry" and no further problems appear.