|
| 01 Aug 2011 05:27 PM |
| So there is nothing on the Wiki directly about the use of the return snippet, and I'd like to know how to use it. In this case, I have a function in a script in a HopperBin called when the player clicks after some conditions. Inside the function, it checks all the parts in a model for a part in a certain position in relation to an existing object. If the part relative to the position of the existing object is false, it adds a part there and returns false. If something is there, return true and do nothing. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
| |
|
|
| 01 Aug 2011 05:33 PM |
function example(arg1,arg2) return arg1+arg2 end
print(example(1,5))
>6 |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2011 05:36 PM |
@Duke: But how can I grab the returned value in another function?
Here is the checker function and its parameters: function checkPos2(target,pos,bool)
Target is mouse.Target from the Button1Down(mouse) function, and pos is the position of target. Bool is the bool I want to grab for the Button1Down function. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 01 Aug 2011 05:38 PM |
| wouldn't it have to return after you check though? |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2011 05:39 PM |
function explode(boom) local pos = boom.Position(math.random(1,100), math.random(1,100), math.random(1,100)) return pos end
print(""..explode(Instance.new("Explosion", workspace)).."") |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2011 05:39 PM |
Yes. I'll just post the check function and let you decide if it's right.
function checkPos2(target,pos,bool) isPart = false mine = game.Workspace.Mine:GetChildren() for i = 1, #mine do if (mine[i].Position == pos + Vector3.new(4,0,0) then isPart == true end end end return isPart end |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 01 Aug 2011 05:42 PM |
function checkPos2(target,pos,bool) local isPart = false mine = game.Workspace.Mine:GetChildren() for i = 1, #mine do if (mine[i].Position-pos).magnitude<=4 then isPart = true end end return isPart end
I still don't see what you need the bool is for? |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2011 05:43 PM |
| I'm writing a script for a mining game like the popular game Epic Mining by PiePerson. I don't want to add a new block where another one already is. |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2011 05:43 PM |
In another function you would have to use an "if" statement.
if checkPos2(target,pos,bool) == true then
--stuff if checkPos2 returns 'true'
else
--stuff if checkPos2 returns 'false'
end |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2011 05:46 PM |
| OK, but what I'm asking is the way I have my check function the right way? |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 01 Aug 2011 05:48 PM |
| Then you would NOT use clicked stuff. First when you generate all the bricks to start, make all of them named by their position. When you dig one out and it's gone, make it so that the brick isn't removed but instead is completely invisible and CanCollide==false. Then you're going to get where the parts for each direction should be by simple vector math. Then once you have all those positions, use :findFirstChild() to find if there's already one and if there isn't make a new brick. |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2011 05:50 PM |
| Yes, I already figured out I can't remove parts, which is why I added the checker. The problem is though is that I'm determining whether the target is an ore or not by the name. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 01 Aug 2011 05:51 PM |
| That's why you name it by the position. |
|
|
| Report Abuse |
|
|
|
| 01 Aug 2011 05:56 PM |
| I could probably make that work. |
|
|
| Report Abuse |
|
|