ID:149086
 
In world.status, I try to use a variable that is defined on Login(), but it says error: expected a constant expression. Yet, in all the tutorials on this, the using of the embedded [] works, 100% true to the usage. How do you fix it? Here's where I use it. The world is on the top.
Host is defined and is redefined in Login()
world/hub = "Drafonis.Fighters"
world
world
name = "Fighters of the Doom World"
status = "Version 9: ADDED A MOVING MOB!: hosted by [Host]!"
mob
Login()
if(usr.key == "Radditz234")
usr << "You're banned!"
world << "The infamous [usr] has attempted to connect at [ReportTime(world.time)], coressponding to [ReportDate(world.realtime)]."
usr << "Buh-bye!"
del(src)
else if(Players == 0)
usr << "You are the first player on!"
usr << sound('login.wav')
usr.icon = 'icon.dmi'
Players = 1
Host = "[usr.key]"
..()
else if(Players >= 1)
world << "[usr] enters!"
usr << "Welcome to [MASTER_KEY]'s FIRST original game. Please donate. BTW, all people with a DBZ name AND have an icon will be banned."
usr << sound('login.wav')
usr.icon = 'icon.dmi'
Players += 1
..()
if(usr.SaveFiles == 1)
var/info //define the info var
var/saved = input("What file would you like to load?") in files //ask which info to load
var/savefile/F = new("list.sav") //define which savefile to load from
F["[saved]"] >> info //load the info
usr << "You have loaded [saved]!"
usr << info //show the user the info
Read(F)
..()
var
Host = 0
Players = 0

All this code has a reference to either Players or Host.
</<></<>
Drafonis wrote:
In world.status, I try to use a variable that is defined on Login(), but it says error: expected a constant expression. Yet, in all the tutorials on this, the using of the embedded [] works, 100% true to the usage. How do you fix it? Here's where I use it. The world is on the top.

The problem is that the world is created before the first mob logs in, so it has no idea what the variable Host might be. You can use a variable in an assignment to status, but not where you placed it. You need to call a proc to set it.

world
proc/set_status()
status = "Version 9: ADDED A MOVING MOB!: hosted by [Host]!"

mob
Login()
// all your other stuff here...
world.set_status()
Drafonis wrote:
In world.status, I try to use a variable that is defined on Login(), but it says error: expected a constant expression. Yet, in all the tutorials on this, the using of the embedded [] works, 100% true to the usage. How do you fix it? Here's where I use it. The world is on the top.
Host is defined and is redefined in Login()
world/hub = "Drafonis.Fighters"
world
world
name = "Fighters of the Doom World"
status = "Version 9: ADDED A MOVING MOB!: hosted by [Host]!"

Why do you have two "world" lines?
Anyway, here's the problem: Using embedded [] only works in procs. You can't use it to initialize a var like you're doing in world.status. What you have to do is set world.status when you set Host.

mob
Login()
if(usr.key == "Radditz234")
usr << "You're banned!"
world << "The infamous [usr] has attempted to connect at [ReportTime(world.time)], coressponding to [ReportDate(world.realtime)]."
usr << "Buh-bye!"
del(src)
else if(Players == 0)
usr << "You are the first player on!"
usr << sound('login.wav')
usr.icon = 'icon.dmi'
Players = 1
Host = "[usr.key]"

Here's where you'd set world.status.

Lummox JR
In response to Skysaw
Skysaw wrote:
Drafonis wrote:
In world.status, I try to use a variable that is defined on Login(), but it says error: expected a constant expression. Yet, in all the tutorials on this, the using of the embedded [] works, 100% true to the usage. How do you fix it? Here's where I use it. The world is on the top.

The problem is that the world is created before the first mob logs in, so it has no idea what the variable Host might be. You can use a variable in an assignment to status, but not where you placed it. You need to call a proc to set it.

world
proc/set_status()
status = "Version 9: ADDED A MOVING MOB!: hosted by [Host]!"

mob
Login()
// all your other stuff here...
world.set_status()

Your code works at compile-time, but it fails at run-time. I hosted, and I was the first player, but the world status wasn't set.
In response to Lummox JR
Lummox JR wrote:
Drafonis wrote:
In world.status, I try to use a variable that is defined on Login(), but it says error: expected a constant expression. Yet, in all the tutorials on this, the using of the embedded [] works, 100% true to the usage. How do you fix it? Here's where I use it. The world is on the top.
Host is defined and is redefined in Login()
world/hub = "Drafonis.Fighters"
world
world
name = "Fighters of the Doom World"
status = "Version 9: ADDED A MOVING MOB!: hosted by [Host]!"

Why do you have two "world" lines?
Anyway, here's the problem: Using embedded [] only works in procs. You can't use it to initialize a var like you're doing in world.status. What you have to do is set world.status when you set Host.

mob
Login()
if(usr.key == "Radditz234")
usr << "You're banned!"
world << "The infamous [usr] has attempted to connect at [ReportTime(world.time)], coressponding to [ReportDate(world.realtime)]."
usr << "Buh-bye!"
del(src)
else if(Players == 0)
usr << "You are the first player on!"
usr << sound('login.wav')
usr.icon = 'icon.dmi'
Players = 1
Host = "[usr.key]"

Here's where you'd set world.status.

Lummox JR

The two "world"s are merely from habit. The don't seem to affect, neither at run-time nor at compile-time.
In response to Drafonis
Drafonis wrote:
Your code works at compile-time, but it fails at run-time. I hosted, and I was the first player, but the world status wasn't set.

If the proc was called, the status was set. It may need to be called after you push the host button to be visible on the hub listing. You may also need to refresh the hub page to see it update.
In response to Skysaw
Skysaw wrote:
Drafonis wrote:
Your code works at compile-time, but it fails at run-time. I hosted, and I was the first player, but the world status wasn't set.

If the proc was called, the status was set. It may need to be called after you push the host button to be visible on the hub listing. You may also need to refresh the hub page to see it update.

I checked. Still won't state that, even after the refreshing of the hub page.
In response to Drafonis
Drafonis wrote:
Skysaw wrote:
Drafonis wrote:
Your code works at compile-time, but it fails at run-time. I hosted, and I was the first player, but the world status wasn't set.

If the proc was called, the status was set. It may need to be called after you push the host button to be visible on the hub listing. You may also need to refresh the hub page to see it update.

I checked. Still won't state that, even after the refreshing of the hub page.

Do you call the proc after you push the host button?
In response to Skysaw
Skysaw wrote:
Drafonis wrote:
Skysaw wrote:
Drafonis wrote:
Your code works at compile-time, but it fails at run-time. I hosted, and I was the first player, but the world status wasn't set.

If the proc was called, the status was set. It may need to be called after you push the host button to be visible on the hub listing. You may also need to refresh the hub page to see it update.

I checked. Still won't state that, even after the refreshing of the hub page.

Do you call the proc after you push the host button?

Not sure how to.