Hey all, I noticed that some people have really got a knack for turning scripts into single CYOB blocks... could any of you have a go at this? it would really help

(clicking "view image" and then magnifying it should make it the full size)
the yellow reporter at the bottom is what the block looks like in the end
Last edited by sparks (2010-08-10 17:07:40)
Offline
BTW you should zoom it in
Offline
it does this: the file has tags for areas like this:
<shelf>
then it has items, with values. first a from-to number out of 99 to indicate how likely they are to get picked (two digits) then three digits that indicate the maximum and minimum value of the objects (three for max and three for min) then the name.
so
<shelf>
0050010020bottle
5199000200bag
</shelf>
the block will pick a random number from o to 99. say it's 32. 32 is more than 00 and less than 50 so bottle is selected, not bag. next the value of the bottle (such as contents in mm) is chosen with another random from it's max to it's min (010 to 020) then the random value and the name is reported... e.g. "015,bottle"
Offline
how to do repeat until I have a meathod but not the most practical...
Offline
Here without a few things:
Name:
choose from file $String$ with tag $String$
Type
-r
Code:
| homearea tag choice count level output temp temp2 temp3 temp4 temp5 |
homearea_ t1.
tag_ t2.
choice_ self randomFrom: (0) to: (99).
count_ 0.
"Start Repeat Until t2 = true"
count_ count + 1.
temp_ self readLine: (count) ofFile: (homearea).
temp2_ self concatenate: ('<') with: (tag).
temp2_ self concatenate: (tag) with: ('>').
temp = temp2
ifTrue: [
temp2_ true.
]
ifFalse: [
temp2_ false.
].
"End repeat until"
count_ count + 1.
"Start Repeat Until t2 = true"
temp_ self readLine: (count) ofFile: (homearea).
temp2_ self concatenate: ('</') with: (tag).
temp2_ self concatenate: (tag) with: ('>').
temp = temp2
ifTrue: [
temp2_ true.
]
ifFalse: [
temp2_ false.
].
temp4_ 0.
temp2_ self letters: (3) through: (4) of: (temp).
temp2 > choice
ifTrue: [
temp4_ 99
].
temp2 = choice
ifTrue: [
temp4_ temp4 + 33.
].
temp2_ self letters: (1) through: (2) of: (temp).
temp2 < choice
ifTrue: [
temp4_ temp4 + 33.
].
temp2 = choice
ifTrue: [
temp4_ temp4 + 33.
].
temp4_ temp4 + 1.
temp4 = 200
ifTrue: [
temp4_ true.
].
temp4 = 100
ifTrue: [
temp4 _ true.
].
temp4 = true
ifFalse: [
temp4_ false.
].
temp4 = true
ifTrue: [
name_ self readLine: (count) ofFile: (homearea).
level_ self stringLength: (name).
name_ self letters: (11) through: (level) of: (name).
level_ self readLine: (count) ofFile: (homearea).
temp5_ self letters: (5) through: (7) of: (level).
level_ self letters: (8) through: (10) of: (level).
level_ self randomFrom: (temp5) to: (level).
"Stop Script"
].
count_ count + 1.
"End Repeat Until "
output_ self concatenate: (level) with: (',').
output_ self concatenate: (output) with: (name).
^ output.
Offline
I wrote some of it, refreshed my browser, then ....
I think it works
Tested it, it does! YAY!
chooseFrom: t1 tag: t2
| code i j arr item getItem rnd |
code := self readFile: t1.
i := (code findString: '<',t2,'>') + 2 + t2 size.
j := (code findString: '</',t2,'>') - 1.
code := code copyFrom: i to: j.
arr := OrderedCollection new.
getItem := [:it |
| i0 j0 k0 l0 |
i0 := it findString: '-'.
j0 := it findString: ',' startingAt: i0 + 1.
k0 := it findString: '-' startingAt: j0 + 1.
l0 := it findString: ',' startingAt: k0 + 1.
{(it copyFrom: 1 to: i0 - 1) asNumberNoError.
(it copyFrom: i0 + 1 to: j0 - 1) asNumberNoError.
(it copyFrom: j0 + 1 to: k0 - 1) asNumberNoError.
(it copyFrom: k0 + 1 to: l0 - 1) asNumberNoError.
it copyFrom: l0 + 1 to: it size}].
[(i := code findString: '|') > 0] whileTrue: [
item := code copyFrom: 1 to: i - 1.
arr add: (getItem value: item).
code := code copyFrom: i + 1 to: code size.
].
arr add: (getItem value: code).
rnd := self randomFrom: 0 to: 99.
arr do: [:it |
rnd >= it first & (rnd <= it second) ifTrue: [
rnd := self randomFrom: it third to: it fourth.
^ rnd asString,',',it fifth.
].
].
Here, let me indent it.
Oh, and here's the new syntax:
<shelf> 0-50,10-20,bottle|51-99,0-200,bag </shelf>
I think newlines are OK between items.
And that's a PIPE.
Last edited by nXIII (2010-08-10 18:59:32)
Offline
nXIII wrote:
I wrote some of it, refreshed my browser, then ....
I think it works![]()
Tested it, it does! YAY!chooseFrom: t1 tag: t2
| code i j arr item getItem rnd |
code := self readFile: t1.
i := (code findString: '<',t2,'>') + 2 + t2 size.
j := (code findString: '</',t2,'>') - 1.
code := code copyFrom: i to: j.
arr := OrderedCollection new.
getItem := [:it |
| i0 j0 k0 l0 |
i0 := it findString: '-'.
j0 := it findString: ',' startingAt: i0 + 1.
k0 := it findString: '-' startingAt: j0 + 1.
l0 := it findString: ',' startingAt: k0 + 1.
{(it copyFrom: 1 to: i0 - 1) asNumberNoError.
(it copyFrom: i0 + 1 to: j0 - 1) asNumberNoError.
(it copyFrom: j0 + 1 to: k0 - 1) asNumberNoError.
(it copyFrom: k0 + 1 to: l0 - 1) asNumberNoError.
it copyFrom: l0 + 1 to: it size}].
[(i := code findString: '|') > 0] whileTrue: [
item := code copyFrom: 1 to: i - 1.
arr add: (getItem value: item).
code := code copyFrom: i + 1 to: code size.
].
arr add: (getItem value: code).
rnd := self randomFrom: 0 to: 99.
arr do: [:it |
rnd >= it first & (rnd <= it second) ifTrue: [
rnd := self randomFrom: it third to: it fourth.
^ rnd asString,',',it fifth.
].
].Here, let me indent it.
Oh, and here's the new syntax:Code:
<shelf> 0-50,10-20,bottle|51-99,0-200,bag </shelf>I think newlines are OK between items.
And that's a PIPE.
New Syntax? thats a different language. (Looks a bit like an _ML language.
Offline
no, that language just specifically applys to reading these files. I used html <tags> to indacate which area in the file to search.
n, does this mean that rather than writing 0150 (1 to 50) 0's before numbers no longer need to be put in?
Offline
NXIII, your block works really well! the one glitch is that if the item selected is the last item in that tag, it displays it with a blank second line... I overcome this by putting a dummy "0-0,0-0,0" item at the end that cannot be triggered. also, it runs a lot faster if all the items are on one line
EDIT: I take that back it does not appear to affect the speed... I did a test
Last edited by sparks (2010-08-11 06:17:02)
Offline
sparks wrote:
NXIII, your block works really well! the one glitch is that if the item selected is the last item in that tag, it displays it with a blank second line... I overcome this by putting a dummy "0-0,0-0,0" item at the end that cannot be triggered. also, it runs a lot faster if all the items are on one line
EDIT: I take that back it does not appear to affect the speed... I did a test
![]()
Oh, cool!
I didn't test it much, just looked to see if it gave something that looked right
.
Offline