Author Topic: [Scripts] Considering adding a return value to scripts  (Read 2463 times)

0 Members and 1 Guest are viewing this topic.

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6496
  • Dig Deep
  • Awards Developer 3 years on site+600 posts 2 years on site+300 posts Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site+100 posts Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
[Scripts] Considering adding a return value to scripts
« on: May 12, 2015, 09:32:24 AM »
I'm considering adding input parameters and return values to scripts.

This would help modularize certain functions.

e.g. Some scripts utilizing return values

script: Validate Something
return [bool]
if
   has..
   has..
   is..
then
   return [true];
else
   return [false];

script: Script1
if
   script [validate something]
then
   validate returned true
else
   validate returned false


script: Script2
if
   script [validate something]
then
   validate returned true
else
   validate returned false

Script1 and Script2 are able to use the same validation without having to write it twice.

Another example:

Script: GetRandomMobType
return [mobtype]
if
   israndom [1,3]
then
   return [sheep]
elseif
   israndom [1,3]
then
   return [duck]
else
   return [highlandcow]

script: SpawnRandomMob
spawnmob [x,y,z] [script:GetRandomMobType]


e.g. Some scripts utilizing input parameters

script: SpawnMob
input [point] point
input [mobtype] mobtype
spawnmob [point] [mobtype]

script:SpawnRandomMob
if
   israndom [1,3]
then
   script [SpawnMob] [100,200,100] [sheep]
elseif
   israndom [1,3]
then
   script [SpawnMob] [200,200,100] [duck]
else
   script [SpawnMob] [100,200,200] [diablo]


possible input/return types would be something like:
Bool (true or false)
Value (a number)
Point (x,y,z)
Color
MobType
BlockID
ItemID
and probably several others

My thinking with this is still undeveloped and there may well be problems that could make it infeasible, but so far i think it could be done.

Thoughts?
« Last Edit: May 12, 2015, 09:35:43 AM by Craig »

TM Charles

  • Supreme Member
  • *****
  • Posts: 2051
  • Awards Was in the top 10 of the forum stats page as of 4/12/15 Donated a giveaway prize. (Must be a prize of cash value.) 2 years on site+300 posts 1 year on site+100 posts
    • View Profile
    • ::)
    • Awards
  • Xbox: ETTP & Mr Zincy
Re: Considering adding a return value to scripts
« Reply #1 on: May 12, 2015, 10:20:41 AM »
I think this can open the minds of many also this will make scripts more open to a lot with these new options



TheDestinedCrab

  • Legendary Member
  • *****
  • Posts: 1244
  • Did you see that? Me neither.
  • Awards 2 years on site+300 posts 1 year on site+100 posts
    • View Profile
    • Awards
Re: Considering adding a return value to scripts
« Reply #2 on: May 12, 2015, 10:21:43 AM »
This sounds good, I can imagine it being good in scripting, very useful. Great idea
Thanks Gold Knight for the amazing sig!

Father Dryymas

  • Supreme Member
  • *****
  • Posts: 4120
  • What's yours is mine. ~TM's Resident Master Thief~
  • Awards Members who have unlocked the robotic avatar Awarded to exemplary forum members 2 years on site+300 posts Site art contributions/TPs in-game/Contest winners 1 year on site+100 posts
    • View Profile
    • Awards
  • Xbox: dryym
Re: Considering adding a return value to scripts
« Reply #3 on: May 12, 2015, 08:09:01 PM »
This, Combined with Relative to Players/Mobs, Would open up so many doors for many people.


Just a thought. This could theoretically be used for coordinate specific history, That could be used for repastable one use per player systems, With little or no editing of scripts, Each time you use a new one.
« Last Edit: May 12, 2015, 08:27:55 PM by Dryym »

Creator of the term "Deathmine "
Jared [19|Oct 07:12 PM]: "It changes everything" Dryym

muD

  • Legendary Member
  • *****
  • Posts: 1177
  • Awards Members who have unlocked the robotic avatar Awarded to exemplary forum members Day 1 w/25+ posts (4/12/13) 2 years on site+300 posts Former MotM winners 1 year on site+100 posts
    • View Profile
    • Awards
Re: Considering adding a return value to scripts
« Reply #4 on: May 14, 2015, 10:52:04 AM »
this sounds interesting..
Could you give another example of utilizing input parameters, and an example of how Value can be used pl0x?

muD

  • Legendary Member
  • *****
  • Posts: 1177
  • Awards Members who have unlocked the robotic avatar Awarded to exemplary forum members Day 1 w/25+ posts (4/12/13) 2 years on site+300 posts Former MotM winners 1 year on site+100 posts
    • View Profile
    • Awards
Re: Considering adding a return value to scripts
« Reply #5 on: May 20, 2015, 07:23:11 PM »
I'm intrigued to know if this will allow a method of returning the value of history marks, items in inventory ect in a way which can be directly used by other scripts.

ie. being able to count an entity such as the players history record, then use that value in another script.

eg. player runs a script which counts their mobkill count - they have 7,215 history marks from mob kills. that value 7215 can be accessed by another script to notify the player of their kill count.

Is that something that can be done with this?

Jaz

  • Supreme Member
  • *****
  • Posts: 2934
  • ヽ(`⌒)ノ
  • Awards Awarded to exemplary forum members 3 years on site+600 posts Was in the top 10 of the forum stats page as of 4/12/15 Former MotM winners Donated a giveaway prize. (Must be a prize of cash value.) 2 years on site+300 posts 1 year on site+100 posts
    • View Profile
    • cluckinbellhappychicken
    • Awards
  • Xbox: Jaz the MAN 2
  • PSN: Jaz_the_MAN_2
  • Steam: Jaz the MAN 2
Re: Considering adding a return value to scripts
« Reply #6 on: July 27, 2015, 06:00:39 AM »
I'm intrigued to know if this will allow a method of returning the value of history marks, items in inventory ect in a way which can be directly used by other scripts.

ie. being able to count an entity such as the players history record, then use that value in another script.

eg. player runs a script which counts their mobkill count - they have 7,215 history marks from mob kills. that value 7215 can be accessed by another script to notify the player of their kill count.

Is that something that can be done with this?
If so, it is something I have always tried to do with scripts ::)

"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones" ~ Albert Einstein

Father Dryymas

  • Supreme Member
  • *****
  • Posts: 4120
  • What's yours is mine. ~TM's Resident Master Thief~
  • Awards Members who have unlocked the robotic avatar Awarded to exemplary forum members 2 years on site+300 posts Site art contributions/TPs in-game/Contest winners 1 year on site+100 posts
    • View Profile
    • Awards
  • Xbox: dryym
Re: Considering adding a return value to scripts
« Reply #7 on: November 30, 2015, 08:42:07 AM »
I just thought of another way the return value could be used with 2.43 scripts.

"If
   Intersect [Sphere] [vrel:15,0,0] [12] [Players]
Then
   Context [Player] [Target]
   Script [ReturnPoint]
EndIf

If
   Intersect [Ray] [vrel:15,0,0] [ReturnedPoint] [Players]
Then
   Context [Player] [Target]
   Dostuff..."

This tests if there is a player intersecting the bounding box of a sphere, If they are, It runs a script on them that returns their current location, The script then tests if they intersect with a ray from the centre of the sphere, The purpose of this is to determine if there are any blocks in between the centre of the sphere, And the player.

Creator of the term "Deathmine "
Jared [19|Oct 07:12 PM]: "It changes everything" Dryym

PWRBTTN

  • Legendary Member
  • *****
  • Posts: 1143
  • Professional Expert, Comrade
  • Awards Awarded to exemplary forum members 2 years on site+300 posts Site art contributions/TPs in-game/Contest winners 1 year on site+100 posts
    • View Profile
    • Awards
  • Xbox: PWRBTTN
  • Steam: PWRBTTN
Re: Considering adding a return value to scripts
« Reply #8 on: July 20, 2016, 12:56:54 PM »
Hey, Craig. I know we could jury rig something like this using variables in 2.44, but I feel like this in itself could have a use alongside, or even seperate from variables. So... have you fiddled with this much? It'd be nice to see this.
/snail       /snail    /snail         /snail /snail      /snail   /snail                /snail         

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6496
  • Dig Deep
  • Awards Developer 3 years on site+600 posts 2 years on site+300 posts Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site+100 posts Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
Re: Considering adding a return value to scripts
« Reply #9 on: December 30, 2016, 07:09:27 AM »
This is no longer needed as variables can be returned.

Father Dryymas

  • Supreme Member
  • *****
  • Posts: 4120
  • What's yours is mine. ~TM's Resident Master Thief~
  • Awards Members who have unlocked the robotic avatar Awarded to exemplary forum members 2 years on site+300 posts Site art contributions/TPs in-game/Contest winners 1 year on site+100 posts
    • View Profile
    • Awards
  • Xbox: dryym
Re: Considering adding a return value to scripts
« Reply #10 on: December 30, 2016, 07:55:25 AM »
This is no longer needed as variables can be returned.

Technically, Unless all inputs that require strings are allowed to use numeric IDs, There will always be something that this can do that isn't possible.


An example being the SpawnRandomMob script from the OP.

Another example being a script which gives the player a random item, Or places a random block.

Creator of the term "Deathmine "
Jared [19|Oct 07:12 PM]: "It changes everything" Dryym