Create a free account to remove all ad content.

Author Topic:  Foreach Loop  (Read 477 times)

0 Members and 1 Guest are viewing this topic.

MrMarooca

  • Modder
  • Sr. Member
  • *
  • Posts: 374
  • C# 4 lyfe
    • View Profile
    • YouTube - MrMarooca
  • Xbox: MrMarooca
  • Steam: TheWhitestBoyYouKnow
Foreach Loop
« on: December 04, 2015, 09:27:15 PM »
A foreach loop is a type of loop that iterates through a collection (such as an array or list) and runs a series of code/commands every time an item is found in said collection.

Example using C#

//Create a string array of developer names.
string[] developerNames = { "Craig", "Campbell", "Baldy", "martindoolittle" };

// For every string found inside the array, display a messagebox with the developer's name.
foreach(string name in developerNames)
{
    MessageBox.Show(name);
}


-----------------------------------------------------------------------------

Example syntax for Toal Miner scripting:

Foreach = Collection to iterate through.
Do = Command(s) to execute.
EndForeach = Indicates the end of a foreach loop.


Foreach
    History [historyName] [player]

Do
    Health [player] [+10]
    Notification [local] [+10 Health!]

EndForeach



This script would add 10 health to the player for every count of the "historyName" attribute found in the player's history.

-----------------------------------------------------------------------------

Other Uses:
Spoiler for Hidden Content:
Iterate through gold pieces in a player's inventory, add a history count each time an GP is found and finally, notify how many GP's were found.

Quote
ForEach
    HasInventory [player] [GoldPieces] [true]
Do
    History [gp] [player]
EndForeach

Notify [[gamertag] has [history:gp]!
« Last Edit: December 05, 2015, 08:57:18 PM by MrMarooca »
You want me to give a timeframe? haha I'd have more luck predicting the end of the world.

Faint of Clubs

  • Sr. Member
  • *
  • Posts: 364
    • View Profile
  • Xbox: Faintcub7332217
Re: Foreach Loop
« Reply #1 on: December 04, 2015, 10:32:25 PM »
Craig prolly knows what you mean, but to simplify it for everyone can I suggest:

History text substitution  for values such as queries and health commands?

Example
History player is damage -100

Health [[history:damage]]

This would subtract 100 hp as the history is negative.
A positive history would add hp.

Now the other way it could be used
If
Has inventory [item] [>=] [history:itemcapacity]
Then
Clear extra items?


Would that be similar Marooca?


Edit: ideally this could be used for any integer value in the game
« Last Edit: December 04, 2015, 10:41:47 PM by Faint of Clubs »
That guy with dem scripts.

Dryym

  • Supreme Member
  • *
  • Posts: 4336
  • What's yours is mine. ~TM's Resident Master Thief~
    • View Profile
  • Xbox: dryym
Re: Foreach Loop
« Reply #2 on: December 05, 2015, 07:41:47 AM »
I could definitely use this, I've been wanting to add a weight system to my survival engine, But in order to do so I would need a ForEach loop for every item in my inventory.

Creator of the term "Deathmine "
Jared [19|Oct 07:12 PM]: "It changes everything" Dryym

Gary

  • Tester
  • Supreme Member
  • *
  • Posts: 2942
  • Steam: Conmaan ... ... Discord: Conmaan #9586
    • View Profile
Re: Foreach Loop
« Reply #3 on: December 05, 2015, 08:35:00 PM »
Great suggestion, with a lot of potential uses.

The dark blue in the OP is a little hard to read. Might want to change the color on that to something else.


               

Link to my youtube channel:
https://www.youtube.com/channel/UCo4rmelSOUB9YMM0Is-zWyQ

xTokioBeatlex7

  • Elite Member
  • *
  • Posts: 537
  • Here to Help!
    • View Profile
  • Xbox: xTokioBeatlex
Re: Foreach Loop
« Reply #4 on: December 07, 2015, 08:36:15 AM »
I like this. It is also very practical in nature and is useful. +1
Definitely not a Destructo-Kitten.

SHAdowboRn77

  • Member
  • *
  • Posts: 103
  • We are born in the shadows.
    • View Profile
  • Xbox: SHAdowboRn77
Re: Foreach Loop
« Reply #5 on: December 08, 2015, 06:32:24 PM »
Sounds very useful, Great idea!
I am not him, I am his shadow.

Faint of Clubs

  • Sr. Member
  • *
  • Posts: 364
    • View Profile
  • Xbox: Faintcub7332217
Re: Foreach Loop
« Reply #6 on: December 20, 2015, 12:49:16 AM »
+1
That guy with dem scripts.