Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

New to the whole function thing


dragonlord52
 Share

Recommended Posts

For some reason this isn't working, can any of you help me with this? Since calling a function would be easier then typing out the same code over and over I would like to try to make this work. Yes, I am aware that there are codes for this already out there but that's not gonna help me learn as if I can't write a simple function then I wont be able to write a complex one when the time comes.

All help is appreciated. Here is my script:

> '\\\\\\\\\\\\\\\\\ GET FREE SLOT SCRIPT ////////////////////////
> Function GetFreeItemSlot(Index)
> slot = 1
> Do While int(slot) < 25
> If GetPlayerInvItemNum(Index, Int(slot)) = 0 Then
> slot = 25
> GetFreeItemSlot(Index) = 1
> End If
> Loop
> End Function
> '//////////////// END FREE SLOT SCRIPT \\\\\\\\\\\\\\\\\\\\\\\\\

And here is the Case:

> Case 5
> If GetFreeItemSlot(Index) = 1 Then
> Call PlayerMsg(Index, "Win", 14)
> Else
> Call PlayerMsg(Index, "Fail", 14)
> End If
> Exit Sub

Thanks
Link to comment
Share on other sites

fff, can't believe no one noticed these. There are a couple problems with your function:

1) INFINITE LOOPS DETECTED (you're not incementing the vlue so it's staying at 1 the whole time)

2) It desn't reurn 0 i there aren't any slots.

and so:

Function GetFreeItemSlot(Index)
  GetFreeItemSlot=0
  slot = 1
  Do While int(slot) < 25
      If GetPlayerInvItemNum(Index, Int(slot)) = 0 Then
        slot = 25
        GetFreeItemSlot = 1
        exit function
      End If
      slot = slot + 1
  Loop
  GetFreeItemSlot = 0
End Function
Link to comment
Share on other sites

Lol, stop making me remove my posts.

Just random bugs. You need to declare a variable before using it, its just the way programming languages work.

EDIT

Mods, he's not quadruple posting btw, I just removed my posts. No warning required.

That was my last post.

Already found the error, I just keep removing my posts because I'm saving 1337 for something.

Anyway, I'm off to bed.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...