Another qustion about sugercube [widget]

I try make a system about buliding, it see like not have mistake but it call me

Error: <<Bulids>>: errors within widget contents (Error: <<print>>: bad evaluation: State.variables.bulid_non is undefined; Error: <<for>>: unsupported range expression type: undefined)

it code in next:

::Bulid_The_power
<<set $bulid_non to [
    "树枝拒马",
    "壕沟"
]>>
<<set $recver_power to 0>>

::Bilud
    <div style="height:200px;width:500px;overflow:auto;">
    <<Bulids>>
    </div>
Built: <<= $build_over >>

::Bulid_widget[widget]
<<widget "Bulids">>
        <<print $bulid_non[0]>>
<<nobr>>
    <<for _i,_name range $bulid_non>>
    <<capture _i>>
        <<print _i+1>>._name
        <<button "建造" >>
            <<if _i eq "树枝拒马">>
                <<set $recver_power += 5>>
                <<set  $bulid_non.push(_name)>>
            <</if>>
        <</button>>
    <</capture>>
    <</for>>
<</nobr>>
<</widget>>
:: StoryInit 
<<newinv $pillShop>>
<<newinv $packsack>>



<<set $attack_power to 6>>
<<set $health to 20>>
<<set $spir to 100>>
<<set $flee to 0>>



<<include [[ObjectInit]]>>
<<include [[ShopInit]]>>
<<include [[AttackInit]]>>
<<include [[Cache]]>>
<<include [[Like]]>>
<<include [[Bulid_The_power]]>>

and I include in a secen like this:

<<include [[Bilud]]>>

but what is reason of this? I use tweego and my sugercube version is 2.30.0.(yes yet me)

In your <<Bulids>> widget definition the _i temporary variable contains the Numerical index of the current for loop iteration, which you are using to display a number before each “Name” you are displaying.

But within the body of the <<button>> macro call you are comparing the captured Numerical value of _i to a String value, specifically one of the potential “Name” values. And those two values will never be equal, so that if condition will never be true.

I believe you really want to be capturing the value of the _name Temporary variable, instead of that of _i. And need to change your comparison to also use that captured _name instead of _i value. Capturing _name will also make the updating of the $bulid_non Array possible.

eg, you widget should look more like…

<<widget "Bulids">>
	<<print $bulid_non[0]>>
	<<nobr>>
		<<for _i, _name range $bulid_non>>
			<<capture _name>>
				<<print _i + 1>>._name
				<<button "建造" >>
					<<if _name eq "树枝拒马">>
						<<set $recver_power += 5>>
						<<set  $bulid_non.push(_name)>>
					<</if>>
				<</button>>
			<</capture>>
		<</for>>
	<</nobr>>
<</widget>>
1 Like

yes, but it main question is it non find the “$bulid_non”. so i fix the for it yet call error xwx.

emmm, Maybe it is question of tweego?

What is the structure of the folders you’re storing the files of your Twee Notation based project in?
What command are you using to execute tweego?

it look like this:

 src
│   ├── 商店.twee
│   ├── 野性人生.twee
│   ├── Buliding.twee
│   ├── css
│   │   └── black.css
│   ├── Data
│   │   ├── 采集.twee
│   │   ├── 战斗.twee
│   │   ├── Cache..twee
│   │   ├── enemy
│   │   │   └── enemy.twee
│   │   ├── exploe.twee
│   │   ├── explor_regin
│   │   │   └── dastry_hole.twee
│   │   ├── Like.twee
│   │   ├── Object
│   │   │   └── use.twee
│   │   └── Shop
│   │       └── Object.twee
│   ├── JS
│   │   ├── exploe.js
│   │   └── init.js
│   ├── PassageHeader.twee
│   ├── Slave.twee
│   ├── Story
│   │   ├── 第二次接触原住民(豹子).twee
│   │   ├── 恶魔时间.twee
│   │   └── 原住民事件.twee
│   └── StoryInit.twee
└── test.html

the mistake put in “Buliding.twee”.
and I use commend :

 tweego -o test.html src --watch --test 

emmm, it look some confusion, I use more Chinese name in early.xwx

Is there a reason why this file has two consecutive full-stops in its name?

And the contents of the StoryInit special Passage is in this file?

yes,And it display in top of this page.

Ah shit. I know what is the reason about this, it is so foolish, I use the save to test. but save don’t record the new variable in StoryInit, if i anew, this system is able.