HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Running a trigger in a FOR loop?

08-10-2002, 04:49 PM#1
Guest
I was actually going to make a leaderboard with the value "lifes" for an RPG. I only wanted it to list all User controlled Playing players, so I made a trigger instead of a very complex For loop.
The map initialisation calls the trigger with a For each B loop:
For each (Integer B) from 1 to 12, do (Trigger - Run Player Init <gen> (checking conditions))

Player Init has no event, but a condition:
(((Player((Integer B))) slot status) Equal to Is playing) and (((Player((Integer B))) controller) Equal to User)
The actions are:
Player Group - Add (Player((Integer B))) to ActivePlayers
Set PlayerName[(Integer B)] = (Name of (Player((Integer B))))
Leaderboard - Add (Player((Integer B))) to LifeLeaderboard with label PlayerName[(Integer B)] and value 3

The actions "create leaderboard" is run before the loop and the action "show leaderboard" after it along with the "sort leaderboard" action. The leaderboard is shown to 'All players' (in the create action) and should work. However it stays empty. It appears, but without any content.
Maybe I've just missed some detail again or maybe the integers A and B aren't transfered to triggers run by their loops...
08-10-2002, 05:41 PM#2
Guest
The problem, I think, is timing.

The for loop in the map init trigger needs only to begin running the Player Init function for it to consider it's job done. It is not waiting for Player Init to complete running. So what happens is, the For loop shoots off 12 instances of Player Init before the first instance of Player Init is finished running. If you had a player 12 or maybe 11 in the game, that player would likely be the only one to show up on the scoreboard because by the time the Player Inits execute their actions, Integer B is already up around there.

I would suggest using 3 for loops in the Player Init function, one for each action you want done. Then just call Player Init from the map init trigger. It's not as efficient as your way, but it will work.

It's too bad For Loops and If/Thens only allow one action in the statement.
08-10-2002, 05:47 PM#3
Guest
Ugh. Great. That means I'll have to rescript the whole thing because you can't paste trigger actions into loops via copy/paste.

Oh, well. First I'll go and watch Eight Legged Freaks. Then I'll take another look at it.
08-10-2002, 06:07 PM#4
Newhydra
Actually you can copy/paste into loops if you convert it to custom text...What you also might want to consider is using the trigger queue...In other words, rather then calling the player init trigger add it to the queue, and then at the end of player init remove it from the queue, Make 2 new triggers one to show leaderboard and one to sort it (1 line triggers) and rather then calling the function show leaderboard add the show leaderboard trigger you just made to the queue...
08-11-2002, 12:49 AM#5
Guest
I'm working with text enough when programming PHP in Notepad, so no, converting it to text is not an option for me. The couple of extra clicks are okay.

I've gotten it work now with the tripple-loop method Aur mentioned. I split it up to three loops and it works great.
I've even reduced the "delete unused units" trigger to a single action and put it into the first loop's "else" field.

The only problem was that I had to put a "wait" action between each loop - possibly because they are all B loops.
08-11-2002, 12:55 AM#6
Guest
Actually, your problem is that Integer B doesnt move between variables (or in programming terms Static Functions). I actually have no idea why u included run the trigger. For each Actions copy the For Loop and modify the "then do: "
Dont overcomplicate that which is already challenging for most people.
GOod Luck with ur map.
08-11-2002, 01:05 AM#7
Guest
On a sidenote I've just found a feature too few RPGs are using: handicaps.
With a handicap you can actually make enemies more powerful depending on eg. the amount of players.
EX (with Player 12 being the bad guys):
Player - Set Player 12 (Brown) handicap to (100.00 x (Square root((Real((Number of players in ActivePlayers))))))%
Square root because of balance issues (having two players doesn't mean they can do twice the damage and take twice the hits).
08-11-2002, 11:02 AM#8
Khaoz
awe!! So much for me being the only one who realized that features potential in an rpg.....

Oh well lets hope my map is the first one out to use it :D
08-11-2002, 12:42 PM#9
Guest
I'm also basing the experience gain on that. Since there are less enemies per player using this technique, they should give more experience. Thank god I've toyed around with PHP a LOT before that. That's probably also the reason I find the whole cascading trigger stuff rather fun than complicated. Doing all that with TEXT instead of the semi-graphical interface would be challenging tho.