Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: free variable 'i' referenced before assignment in enclosing scope #13

Closed
lomnom opened this issue Jun 11, 2023 · 1 comment
Closed

Comments

@lomnom
Copy link

lomnom commented Jun 11, 2023

> datapack build Farting.mcf
Traceback (most recent call last):
  File "/home/lomnom/.local/bin/datapack", line 8, in <module>
    sys.exit(run())
  File "/home/lomnom/.local/lib/python3.9/site-packages/datapack/cli.py", line 63, in run
    _run_build(args)
  File "/home/lomnom/.local/lib/python3.9/site-packages/datapack/cli.py", line 107, in _run_build
    success = compile(outdir, args.files, args.verbose, args.nofiles, args.zip, args.hide)
  File "/home/lomnom/.local/lib/python3.9/site-packages/datapack/compiler.py", line 29, in compile
    namespace.compile(verbose, hide)
  File "/home/lomnom/.local/lib/python3.9/site-packages/datapack/namespace.py", line 145, in compile
    func.commands[i] = self.post_process_line(line, hide)
  File "/home/lomnom/.local/lib/python3.9/site-packages/datapack/namespace.py", line 227, in post_process_line
    callfuncname = self.instantiate_string_function(callfuncname, stringdata)
  File "/home/lomnom/.local/lib/python3.9/site-packages/datapack/namespace.py", line 259, in instantiate_string_function
    copy.compile()
  File "/home/lomnom/.local/lib/python3.9/site-packages/datapack/function.py", line 265, in compile
    self.process_line()
  File "/home/lomnom/.local/lib/python3.9/site-packages/datapack/function.py", line 563, in process_line
    add_param(paramlist[paramindex], expression, entitytags)
  File "/home/lomnom/.local/lib/python3.9/site-packages/datapack/function.py", line 544, in add_param
    augment_int(func.name + '.' + p, self.reference_path(givenparams[i]), '=', self.namespace))
NameError: free variable 'i' referenced before assignment in enclosing scope

Farting.mcf:

randA=#i
randB=#i
randC=#i
randD=#i
def getRandomNums:
	sacrifice=summon marker 0 0 0
	randA=data get entity sacrifice UUID[0] 1
	randB=data get entity sacrifice UUID[1] 1
	randC=data get entity sacrifice UUID[2] 1
	randD=data get entity sacrifice UUID[3] 1
	kill sacrifice

bounded=#i
def bound min#i max#i num#i:
	max-=min
	num%=max
	bounded=min
	bounded+=num

def giveaway player#p itemA#s maxA#i itemB#s maxB#i itemC#s maxC#i itemD#s maxD#i:
	getRandomNums
	bound 0 maxA randA
	give player itemA bounded

	bound 0 maxB randB
	give player itemB bounded
	
	bound 0 maxC randC
	give player itemC bounded
	
	bound 0 maxD randD
	give player itemD bounded

def veganism player#p:
	giveaway player carrot 16 bread 16 baked_potatoes 16 apples 8 

Farting.mcf does not compile, and the compiler crashes abnormally.
Compiles if the function bound is removed.

@emorgan00
Copy link
Owner

Hi, see my recent comment here: #12 (comment)

Also, I think you are trying to do a couple things that aren't supported:

  • randA=data get ... isn't supported by the tool
  • give player itemA bounded isn't supported by minecraft commands, since bounded is not a compile time constant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants