RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[solved]Can this script be abbreviated?

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 82
We learn by living...
So I wrote a simple circle that loops +1 from 1 to 6 and starts back at six, nothing special, but it seems to take a lot of space.

Code: [Select]
@chant_window.fragment = @chant_window.fragment > 5 ? 1 : @chant_window.fragment + 1

I'm just trying to say
Code: [Select]
if @chant_window.fragment > 5
@chant_window.fragment += 1
else
@chant_window.fragment = 1
end

in as few lines as possible.
« Last Edit: May 05, 2011, 11:58:33 PM by shintashi »

pokeball TDSOffline
***
Rep:
Level 84
-T D S-
Silver - GIAW 11 (Hard)Silver - Game In A Week VII
%= should do it, but in your case you might have to add a bit of extra code since it loops back at 0 not to 1.

Something like this.

Code: [Select]
value = 0
for i in 0...20
  value += 1
  value %= 7
  value = [value, 1].max
  p value
end

Of course you would have to apply it to your own example.

Code: [Select]
@chant_window.fragment += 1
@chant_window.fragment %= 7
@chant_window.fragment = [@chant_window.fragment, 1].max

The extra code at the end is because your minimum value is 1.

I hope this helps you out.

Have a nice day.
« Last Edit: May 04, 2011, 05:33:52 AM by TDS »

**
Rep:
Level 71
RMRK Junior
If you want to cycle from 1-6, just change the order...

Code: [Select]
value = 0
for i in 0..20
  value %= 6
  value += 1
  p value
end

**
Rep:
Level 82
Code: [Select]
(0..20).each {|i| value = (i % 6) + 1 }

***
Rep:
Level 82
We learn by living...
whats the 0..20 for?

**
Rep:
Level 82
I was just following the convention of the above posts. Its just an example. You weren't really specific on how many times you need to loop. If you're not looping, and just want to increment by one, and roll over to 1 after hitting six:

Code: [Select]
@chant_window.fragment = ((1 + @chant_window.fragment) % 6) + 1

***
Rep:
Level 82
We learn by living...
I was just following the convention of the above posts. Its just an example. You weren't really specific on how many times you need to loop. If you're not looping, and just want to increment by one, and roll over to 1 after hitting six:

Code: [Select]
@chant_window.fragment = ((1 + @chant_window.fragment) % 6) + 1

that script actually produces a really weird result where every other window is highlighted.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Change it to what FZ had in his first answer and take out the first "1 +". Ie:

Code: [Select]
@chant_window.fragment = (@chant_window.fragment % 6) + 1