hpwControl Plugin - Early Preview for Feedback

Questions about NeoBook PlugIns

Moderator: Neosoft Support

Locked
Guest

hpwControl Plugin - Early Preview for Feedback

Post by Guest »

Just post an early preview of hpwControl:

http://www.hpwsoft.de/anmeldung/html1/n ... ook10.html

I just want to know if such additional control commands to the neobook-sripting are usefull and wellcome.

Feedback please!


(Edited by HPW at 3:46 pm on Feb. 17, 2003)
Last edited by Guest on Sun Mar 06, 2005 2:15 am, edited 1 time in total.
Tom0360

hpwControl Plugin

Post by Tom0360 »

Hans,

Is this to replace the If / Else Statements?

I think if it would create less programming then it is well worth it.  I am still not very good with neobook, would you be willing to break down what the these three lines are doing in your sample pub please.

.hpwCase "[ComboBox1]" "Apples|Oranges|Grapes|Nuts" "Case1"
.hpwCase "[ComboBox1]" "Apples[#013][#010]Oranges[#013][#010]Grapes[#013][#010]Nuts" "Case1"
hpwCase "[ComboBox1]" "[FruitLst]" "Case1"


Thanks for all your hardwork and effort.
Tom
djold1

hpwControl Plugin

Post by djold1 »

This looks great.  Like Tom, I am a little confused by the information that is there and would appreciate a pbreakdown.

Do I understand that the "Case" is working on the object only or can it be used in an open situation like

:Case something

C1
Do this
Return

C2
Do this
Return

No Match
Do This
Return
HPW

hpwControl Plugin

Post by HPW »

It is not a replacment for If/else, it could be used when large amount of If is used. It is based on a discussion topic about wishes for case-statement under neobook suggestions.

hpwCase "[ListBox1]" "[FruitLst]" "Case1"
GotoLine "[hpwCaseReturn]"

[ListBox1] is the variable which will be compared to all member lof the following string-list.

[FruitLst] is a string-list delimited with CRLF. Can come from input-fields. The syntax from the command menu can also be used "Apples|Oranges|Grapes".

"Case1" is an Example string to build a prefix for valid label-names in the script.

In [hpwCaseReturn] is a return-string from the function to get the jump-target.

So a return of "Case1_1" then the first item is equal (=) to [ListBox1]. This goes on to the number of items. When no item is equal a "Case1_Else" is returned. Ther you jump to the place where you handle this situation.

At the END some sort of "Case1_End" is needed to have a target for the end of the case-construct, where the script-flow can continue.

In the final plugin it would be nice to insert the template of the whole construct, like inserting the standard if where the else and endif command is inserted together with the if-line.

djold1

It is not a gosub. From inside a plugin command you have no access to the script-engine, so you can only work with the commandset which is given from neobook. So I can not do what dave does. He can react on return-values from function like menu. There he left out some script line when the third menu is clicked. Or on IF he jumps to the next ELSE.

I can only work with a label-system to navigate through the script by scripting.

Hope it gets a bit clearer now.


(Edited by HPW at 12:52 pm on Feb. 15, 2003)
dirtbag

hpwControl Plugin

Post by dirtbag »

HPW,

I also trying to figure out what exactly the benefits for this. I just went throught the example and checked it out. What benefits would there be using this method than a whole bunch of IF then Statements???

I am just trying to comprehend where this would benefit you and it what way??

I try to analyze some more but any help appreciated...

Thanks
Rick
HPW

hpwControl Plugin

Post by HPW »

The benefit could be a bit more readable code and a one shot setup of the whole code. For 10 items with If you have to insert 10 x if , with case it would one insert.

But again from my first post:
I want to know if such additional control commands to the neobook-sripting are usefull and wellcome.
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

hpwControl Plugin

Post by Gaev »

Hi All:

The subject of a "Case" facility has come up often on this forum ; here is my take on 2 generalised routines that alleviate the need for lots of If ... EndIf snippets

The first routine replaces a bunch of
If "[x]" "=" "1"
    GoSub "LabelA"
EndIf
If "[x]" "=" "2"
    GoSub "LabelB"
EndIf

The second routine replaces a bunch of
If "[x]" "=" "ValueA"
    GoSub "LabelA"
EndIf
If "[x]" "=" "ValueB"
    GoSub "LabelB"
EndIf

------------
Say you have a bunch of subroutines like so ...

:Fruit
AlertBox "FoodGroup" "Fruit !"
Return
:Vegetables
AlertBox "FoodGroup" "Vegetable !"
Return
:Meat
AlertBox "FoodGroup" "Meat !"
Return
:Beer
AlertBox "FoodGroup" "Beer !"
Return
------------

Routine1:

.say you have a list like this
SetVar "[FoodGroupList]" "Fruit,Vegetables,Meat,Beer"

. these 3 commands will invoke a subroutine
. whose label is the "[CaseValue1]" th item in "[FoodGroupList]"
SetVar "[CaseList1]" "[FoodGroupList]"
SetVar "[CaseValue1]" "2"
GoSub "DoCase1"

. [CaseResult]" will be "OK" or "Out of Range"
AlertBox "CaseResult" "[CaseResult]"


. here is the generalised routine "DoCase1"

:DoCase1
. value of [CaseValue1] (1, 2, 3 etc.) identifies the item in array [CaseList1] (ist, 2nd, etc.) that is used as label of GoSub
StrParse "[CaseList1]" "," "[CaseList1Items]" "[CaseList1ItemCount]"

Loop "1" "[CaseList1ItemCount]" "[CaseList1ItemThis]"

If "[CaseValue1]" "=" "[CaseList1ItemThis]"
GoSub "[CaseList1Items[CaseList1ItemThis] ]"       <== remove the extra space !
SetVar "[CaseResult]" "OK"
Return
EndIf

EndLoop
SetVar "[CaseResult]" "Out of Range"
Return


In the example above, since [CaseValue1] = 2, the 2nd label in [FoodGroupList] (i.e. Vegetables) will be GoSub'ed.
------------

Routine2:

.say you have a list like this
SetVar "FoodGroupPairs" "Apples:Fruit,Spinach:Vegetables,Beef:Meat,Heineken:Beer"

. these 3 commands will invoke a subroutine
. whose label is the label (in the value:label pair of values) in "[FoodGroupPairs]"
SetVar "[CaseList2]" "[FoodGroupPairs]"
SetVar "[CaseValue2]" "Beef"
GoSub "DoCase2"


. [CaseResult]" will be "OK" or "Out of Range"
AlertBox "CaseResult" "[CaseResult]"


. here is the generalised routine "DoCase2"

:DoCase2
. value of [CaseValue2] (a, b, c etc.) identifies the key in the "key:label" items in array [CaseList2] ; corresponding label is used in GoSub
StrParse "[CaseList2]" "," "[CaseList2Items]" "[CaseList2ItemCount]"

Loop "1" "[CaseList2ItemCount]" "[CaseList2ItemThis]"
StrParse "[CaseList2Items[CaseList2ItemThis] ]" ":" "[CaseList2Pair]" "[CaseList2PairCount]"  <== remove the extra space !

If "[CaseValue2]" "=" "[CaseList2Pair1]"
GoSub "[CaseList2Pair2]"
SetVar "[CaseResult]" "OK"
Return
EndIf

EndLoop
SetVar "[CaseResult]" "Out of Range"
Return


In the example above, since [CaseValue2] = Beef, the paired label in [FoodGroupPairs] (i.e. Meat) will be GoSub'ed.
------------

That's all folks !
dirtbag

hpwControl Plugin

Post by dirtbag »

i understand a bit more clearly now.. thanks for the info and examples. I think something like this would be useful when needed and can see the benefits it offers now..

Regards,
Rick
HPW

hpwControl Plugin

Post by HPW »

Hello gk51,

Of cource you are right that most things can be done by script. I am only researching/brainstorming if it is possible to make improvment to scripting by a plugin. I have uploaded a new zip with a intergrated example of your Docase1. I have not make all possible Gosub's and this might be a bit more faster when the interpreter have not to jump over many lables with higher values. But with the larger number of testdata you may notice some performance difference. When much comparrison is done by compiled code, it is a bit faster at least with growing amount of data.

On the other side I do not know if it is possible to create subroutines at runtime, as they must be stored in the book/subroutines place.

So in the moment I think it is still worth to do some more thinking on this field.

For true improvment of scripting the one and only who can make it happen is asap dave.

As always! ;-))
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

hpwControl Plugin

Post by Gaev »

Hans-Peter:

I am only researching/brainstorming if it is possible to make improvment to scripting by a plugin.

I did not mean to present my script as a "replacement" for your plug-in ; sorry if it appears so ; during past discussions about the need for a "case" facility (which would be most welcome as a native NeoBook command-set), I had thought about, but never got round to developing a generalised routine ; yesterday, I finally found the spare time to finish it.


... this might be a bit more faster when the interpreter have not to jump over many lables with higher values; but with the larger number of testdata you may notice some performance difference. When much comparrison is done by compiled code, it is a bit faster at least with growing amount of data

My primary objective was to alleviate the large number of If ... EndIf lines of code currently needed to be typed by a Developer ; the number of commands interpreted/invoked by the two methods would be more or less the same ; as well, if using "DoCase1", the whole Loop ... EndLoop segment can be replaced by ...
GoSub "[CaseList1Items[CaseValue1] ]"       <== remove the extra space !

... the additional commands are there to catch "invalid" values ; if performance is an issue, you could
(a) Math "[CaseValue1]" "0" "[CaseValue1]"
(b) Make sure [CaseValue1] is between 1 and [CaseList1ItemCount]
(c) Issue the GoSub


On the other side I do not know if it is possible to create subroutines at runtime, as they must be stored in the book/subroutines place

I don't think I understand ; with either solution, I would expect the Developer to setup a whole bunch of subroutines (in the Book section) before runtime ; in any case, can you not "Call" an external file, which in turn does a "GoToLine" (like in your examples with hpwPlayAction) ? Perhaps, a little more details on the "limitations" with GoSub/Plug-ins might be in order.

For true improvment of scripting the one and only who can make it happen is asap dave

... which would also enable developers to code in-line "case-condition-satisfied" commands, which makes for a much better environment in terms of readability and debuging.

;-))
HPW

hpwControl Plugin

Post by HPW »

I uploaded a new zip. Now hpwCase has another parameter operator. Valid operators  are "=", "<", ">", "<=", ">=". When both sides of the comparrison are number they are compared as floats. With this you can define ranges of numbers which jump to the same Gotoline.
djold1

hpwControl Plugin

Post by djold1 »

Hans-Peter...

I am very much in favor of a Case (Or Select Case) plug-in for NeoBook. I used these in Basic and VB for years and they really eliminate a lot of If/Then/Else statements and also allow logic that If/Else really can't do as well.

I think of Case as:

Select Case Target

  Case is (match or <,<>,>  etc)
  Case Result  (Gosub, print, Option Box, etc)

  Case is
  Case Result

End Case

I have to admit that I am totally baffled by your test .Pub series. I have worked through most of the code but I don't have a clue as to what to enter where, to get any results.

You and gk51 are obviously thinking way ahead of where my scattered mind is at this time.

Please don't let my problem hinder you in your development, however. All this is very good stuff and is putting NeoBook way ahead of others. .
HPW

hpwControl Plugin

Post by HPW »

Hello djold1,

>Select Case Target

>  Case is (match or <,<>,>  etc)
>  Case Result  (Gosub, print, Option Box, etc)

>  Case is
>  Case Result

>End Case

When this should be, it has to be done by asap dave. No way. As a plugin-creator you have to play on the one line of script. Returning from there, you can only use the equipment of neoscript. So a plugin based "Select case" knows nothing about the following code. Therefor a return-value would be needed, which says for example "Hey script, jump to the next following "EndCase" etc.. So as long as we does not  have the top-solution, we can use workarounds by script and plugins. Some not so popular workarounds will stay in this stage and other will find a way to the core on the longrun.

Dave will decide what is best to get into the core. And the rest will be linked on demand through plugin-interface. Not the worst solution I think :-)

My sample pub is at first my testing-platform, where I test the new commands and check logik/usability. So they are not well documented and clear in their design. In this way you can watch a plugin growing over the releases and see influences happens from feedback. I am not the developer sitting in the soft-lab and get out the big-bang final release in late 2003 with demo and documentation.

But if anyone has a better pub showing the use of one of my plugins, it would be great to see them on the neobook resource achive.
djold1

hpwControl Plugin

Post by djold1 »

Thanks Hans-Peter

I understand what you are saying about not being able to make the entire top-to-bottom function as a plug-in.

I will get back to it as I have the time.

Keep going. This is good stuff even if it taxes me a little.
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

hpwControl Plugin

Post by Gaev »

Pete, Hans-Peter:

Here's a thought ...

NeoDeveloper does ...

FileRead "Case1.txt" "All" "[gkParseCase]"
GoSub "gkDoCase"

where Case.txt looks something like ...

SelectCase,[VarPrice]

Case,<,1.00
SetVar "[PurchaseQty]" "200"
Math "[PurchaseQty]*[VarPrice]" "2" "[AmountNeeded]"

Case,<=,[VarAffordable]
SetVar "[AddToShoppingCart]" "[AddToShoppingCart],[VarItem]=[VarPrice]"

Case,>,[VarLimit]
AlertBox "Yikes" "[VarPrice] is over your limit of [VarLimit]"

EndCase


Note: Reason for reading from file is to avoid all the translations for special characters like " [ ] and &#0124;

b) gkDoCase would
-- extract out the NeoBook command lines following a satisfied "Case," condition (until the next "Case," line)
-- then pass the extracted lines to uber plug-in hpwPlayAction


If there is sufficient interest, I can supply gkDoCase
Locked