简体   繁体   中英

Attempt to perform arithmetic on field 'x' when reloading a scene

I'm getting an error message: Attempt to perform arithmetic on field 'x' while trying to reload a scene that I previously loaded.

I found that the error occurs due to the following line:

bg1.x = bg1.x - scrollSpeed

What can I do to fix this issue?

Thanks!

The error full you get is probably something like:

attempt to perform arithmetic on field 'x' (a nil value)

That means you have not initialized bg1.x correctly. Do it, or use a default value like so:

bg1.x = (bg1.x or 42) - scrollSpeed

I chose 42 but you probably want something like 0 ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM