Jump to content

Loops in scripts?


crazytechnokid

Recommended Posts

First of all wow, i signed up about a day ago and already i've posted 3 questions haha. But here's my question. I've made this script and within part of it it checks to see if the player has certain items an acts accordingly (it adds that item). Because its checking around 15 item values i have to put in this basically exact same code chunk 15 times. So is there any way to set up a loop? Where i could have a variable and if that variable equals a certain number that corresponds to a reference and then adds that to the players inventory, and then at the end of the loop adds one to that variable and stops the loop when that variable hits lets say 15? Like for example it would be like this::

int counter
ref item

Do
  if counter == 0
     set item to item1REF
  endif
  if counter == 1
     set item to item2REF
  endif
  etc.

  player.addItem item 1
  set counter to (counter + 1)
While (counter < 16)

Now i know that's more or less using java code but is there a way to do that same basic process in a GECK script? Thank you in advance for any help.

Link to comment
Share on other sites

I don't understand exactly what you're going for, but that thing converted to GECK script would look something like:

 

scn myscriptname

int counter
ref item

Begin GameMode

If counter < 16
  if counter == 0
     set item to item1REF
  endif
  if counter == 1
     set item to item2REF
  endif
  etc.

  player.addItem item 1
  set counter to (counter + 1)
endif

End

 

 

You will want to have another variable to set so that the script doesn't cycle over and over again and just keep adding items (that's what it will do as-is). Without the context it's hard to say what that should be.

You would probably want to change all the endif/if combos into elseifs as well but I would think it would work the same either way.

Link to comment
Share on other sites

What i'm basically trying to do is scan a list of items, if any of the items are enabled they are added to the players inventory. But the problem is i'm doing this for multiple items which makes the script unnecessarily long, while i could acomplish the same thing with much less code in a loop. The code im using to scan the items and act accordingly is this ::

if WRWChineseAssualtREF.getDisabled != 1
	player.addItem weapChineseAssaultRifle 1
	WRWChineseAssualtREF.Disable 1
endif
if WRW10mmPistol.getDisabled != 1
	player.addItem weap10mmPistol 1
	WRW10mmPistolREF.Disable 1
endif
etc. etc. for each item

Now i have to do this for each and every item, Is there a shorter way to do it? Like a loop? I get the code you posted but i don't quite know how to make the script start back at the top of that if statement you posted when it gets to the bottom of that if statement.

Link to comment
Share on other sites

Alright I have FOSE, so would I be able to do something like this?

label allLoop

If counter < 16
  if counter == 0
     set item to item1REF
  elseif counter == 1
     set item to item2REF
  elseif
  etc.

  player.addItem item 1
  set counter to (counter + 1)
  goto allLoop
endif

Link to comment
Share on other sites

Thanks a lot HugePinball for the link, that is exactly what i've been looking for, and thanks Cipscis for the tutorial and examples. Oh and yea i forgot the label had to be an integer when typing that, i realized after posting that it was like writing a .bat file but was to lazy to change that one thing xD. Again thanks everyone for the help, I finally finished the script =).
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...